本文整理汇总了C#中UIFont.WithSize方法的典型用法代码示例。如果您正苦于以下问题:C# UIFont.WithSize方法的具体用法?C# UIFont.WithSize怎么用?C# UIFont.WithSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UIFont
的用法示例。
在下文中一共展示了UIFont.WithSize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMaxFontSize
/// <summary>
/// Gets the maximum font size that will fit the given string within the desired size area.
/// </summary>
/// <returns>The max font size.</returns>
/// <param name="source">Source.</param>
/// <param name="font">Font.</param>
/// <param name="sizeRestriction">Size restriction.</param>
public static float GetMaxFontSize(this string source, UIFont font, SizeF sizeRestriction)
{
// The expected StringSize method doesn't return a useful value for me, so here's a hack.
// NSString.StringSize(font, 0f, ref maximumFontSize, textWidthRestriction, lineBreakMode);
// This is only accurate within a 0.1f value.
float maxFontSize = font.PointSize;
SizeF latest = SizeF.Empty;
using (NSString nssDescriptionWithoutHtml = new NSString(source.ToString())) {
while (latest.Width < sizeRestriction.Width && latest.Height < sizeRestriction.Height) {
latest = nssDescriptionWithoutHtml.StringSize(font.WithSize(maxFontSize), sizeRestriction.Width, UILineBreakMode.Clip);
if (latest.Width < sizeRestriction.Width && latest.Height < sizeRestriction.Height) {
maxFontSize += 0.1f;
}
}
}
return maxFontSize;
}