在iOS 7中替换已弃用的sizeWithFont: [英] Replacement for deprecated sizeWithFont: in iOS 7?
本文介绍了在iOS 7中替换已弃用的sizeWithFont:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在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:
CGSize size = [string sizeWithAttributes:
@{NSFontAttributeName: [UIFont systemFontOfSize:17.0f]}];
// Values are fractional -- you should take the ceilf to get equivalent values
CGSize adjustedSize = CGSizeMake(ceilf(size.width), ceilf(size.height));
这篇关于在iOS 7中替换已弃用的sizeWithFont:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文