在 iOS 7 中,sizeWithFont:
现已弃用。我现在如何将 UIFont 对象传入替换方法 sizeWithAttributes:
?
最佳答案
改用 sizeWithAttributes:
,它现在需要一个 NSDictionary
。使用键 UITextAttributeFont
和您的字体对象传递对,如下所示:
CGRect rawRect = {};
rawRect.size = [string sizeWithAttributes: @{
NSFontAttributeName: [UIFont systemFontOfSize:17.0f],
}];
// Values are fractional -- you should take the ceil to get equivalent values
CGSize adjustedSize = CGRectIntegral(rawRect).size;
https://stackoverflow.com/questions/18897896/