在 iOS 7 中,sizeWithFont:现已弃用。我现在如何将 UIFont 对象传递给替换方法sizeWithAttributes:?
sizeWithFont:
sizeWithAttributes:
改为使用sizeWithAttributes:,现在需要一个NSDictionary. 传入带有 key 的对UITextAttributeFont和你的字体对象,如下所示:
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;