替换已弃用的 sizeWithFont:在 iOS 7 中?

问题描述

改为使用sizeWithAttributes:,现在需要一个NSDictionary. 传入带有 key 的对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;

解决方法

在 iOS 7 中,sizeWithFont:现已弃用。我现在如何将 UIFont 对象传递给替换方法sizeWithAttributes: