In iOS 7, sizeWithFont:
is now deprecated. How do I now pass in the UIFont object into the replacement method sizeWithAttributes:
?
转载于:https://stackoverflow.com/questions/18897896/replacement-for-deprecated-sizewithfont-in-ios-7
In iOS 7, sizeWithFont:
is now deprecated. How do I now pass in the UIFont object into the replacement method sizeWithAttributes:
?
转载于:https://stackoverflow.com/questions/18897896/replacement-for-deprecated-sizewithfont-in-ios-7
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));