objective-c - 替换已弃用的 sizeWithFont : in iOS 7?

在 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/

相关文章:

objective-c - 如何为 NSDate 添加 1 天?

ios - UITableView 单元格选择颜色?

ios - 如何隐藏 iPhone 导航栏上的 'Back' 按钮?

ios - 如何在 iOS 7 上的 UINavigationController 中禁用向后滑动手

ios - 我可以使用 Objective-C block 作为属性吗?

ios - 为什么苹果推荐使用 dispatch_once 来实现 ARC 下的单例模式?

ios - 如何在 Xcode 6 或更高版本中创建类别?

objective-c - 没有 UITableViewController 的 UIRefresh

objective-c - UIView 框架、边界和中心

c - 如何在 C/Objective-C 中将字符串文字拆分为多行?