码迷,mamicode.com
首页 > 移动开发 > 详细

iOS sizeWithFont 过期 is deprecated

时间:2015-09-18 15:23:01      阅读:294      评论:0      收藏:0      [点我收藏+]

标签:

原文: http://www.cnblogs.com/A--G/p/4819189.html

iOS 2.0之后 sizeWithFont就被弃用了,

采用boundingRectWithSize,这里举个栗子~

//计算textview 高度
- (float) heightForTextView: (UITextView *)textView WithText: (NSString *) strText{
    
//    float fPadding = 16.0; // 8.0px x 2
//    CGSize constraint = CGSizeMake(textView.contentSize.width - fPadding, CGFLOAT_MAX);
//    
//    CGSize size = [strText sizeWithFont: textView.font constrainedToSize:constraint lineBreakMode:NSLineBreakByWordWrapping];
    
//    float fHeight = size.height + 16.0;

    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
    paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
    NSDictionary *attributes = @{NSFontAttributeName:textView.font, NSParagraphStyleAttributeName:paragraphStyle.copy};
    
    float fPadding = 16.0; // 8.0px x 2
    CGSize constraint = CGSizeMake(textView.contentSize.width - fPadding, CGFLOAT_MAX);

    CGSize size = [strText boundingRectWithSize:constraint options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size;

    float fHeight = size.height + 16.0;
    
    return fHeight;
}

iOS sizeWithFont 过期 is deprecated

标签:

原文地址:http://www.cnblogs.com/A--G/p/4819189.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!