MonoMobile.Views.StringExtensions.NumberOfLines C# (CSharp) Method

NumberOfLines() public static method

public static NumberOfLines ( this font, string caption, float width ) : int
font this
caption string
width float
return int
		public static int NumberOfLines(this UIFont font, string caption, float width)
		{
			using (var label = new UILabel())
			{	
				var linefeeds = caption.Count(ch => ch == '\n');
				var size = label.StringSize(caption, font);
				
				label.Lines = 1 + ((int)(size.Width / width)) + linefeeds;
				if (size.Width % width == 0)
				{
					label.Lines--;
				}

				return label.Lines;
			}
		}