首页 > 移动平台 > 详细

iOS sizeWithFont 过期 is deprecated

时间:2015-09-18 15:20:08      阅读:189      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!