我正在尝试计算屏幕上将占用多少空间字符串。我正在使用 NSString.StringSize (现在指向sizeWithFont:constrainedToSize:lineBreakMode:
Xamarin.iOS)
UIFont MeasureFont = UIFont.SystemFontOfSize(16f);
private static SizeF MaxMeasureSize = new SizeF(208, float.MaxValue);
//...
string messageBody = "Test";//comes from my dataSource
NSString nsString = new NSString(messageBody);
var textSize = nsString.StringSize(MeasureFont, MaxMeasureSize, UILineBreakMode.CharacterWrap);
Console.WriteLine("Measured -- {0} for [{1}]", textSize, messageBody);
我的应用程序中的输出:
2014-09-05 00:05:20.338 App1[3150:90b] 测量 -- {Width=29.68, Height=19.088} 用于 [Add]
2014-09-05 00:05:20.339 App1 [3150:90b] 测量 -- {宽度 = 29.488,高度 = 19.088} 用于 [测试]
在 PhotoShop 中使用此字体和这些字符串的屏幕截图。显然,字符串 'Test' 比 'Add' 长