替换已弃用的 sizeWithFont: 在 iOS 7 中? [英] Replacement for deprecated sizeWithFont: in iOS 7?
本文介绍了替换已弃用的 sizeWithFont: 在 iOS 7 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 iOS 7 中,sizeWithFont:
现已弃用.我现在如何将 UIFont 对象传递到替换方法 sizeWithAttributes:
中?
In iOS 7, sizeWithFont:
is now deprecated. How do I now pass in the UIFont object into the replacement method sizeWithAttributes:
?
推荐答案
使用 sizeWithAttributes:
代替,它现在采用 NSDictionary
.传入带有键 UITextAttributeFont
和您的字体对象的配对,如下所示:
Use sizeWithAttributes:
instead, which now takes an NSDictionary
. Pass in the pair with key UITextAttributeFont
and your font object like this:
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;
这篇关于替换已弃用的 sizeWithFont: 在 iOS 7 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文