sizeWithFont: in iOS 7过期后如何替换
以前的写法
1 NSString *text = ...; 2 CGFloat width = ...; 3 UIFont *font = ...; 4 CGSize size = [text sizeWithFont:font 5 constrainedToSize:(CGSize){width, CGFLOAT_MAX}];
替换成新的写法
1 NSString *text = ...; 2 CGFloat width = ...; 3 UIFont *font = ...; 4 NSAttributedString *attributedText = 5 [[NSAttributedString alloc] 6 initWithString:text 7 attributes:@ 8 { 9 NSFontAttributeName: font 10 }]; 11 CGRect rect = [attributedText boundingRectWithSize:(CGSize){width, CGFLOAT_MAX} 12 options:NSStringDrawingUsesLineFragmentOrigin 13 context:nil]; 14 CGSize size = rect.size;