美文网首页
ios中计算文本高度

ios中计算文本高度

作者: 三米板 | 来源:发表于2019-09-24 16:41 被阅读0次
-(CGFloat)heightForCellLable:(NSString *)text
{
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
    NSDictionary * attributes = @{
                                  NSFontAttributeName:[UIFont systemFontOfSize:14],
                                  NSParagraphStyleAttributeName: paragraphStyle
                                  };
    CGSize textRect = CGSizeMake([UIScreen mainScreen].bounds.size.width - 50, MAXFLOAT);
    CGFloat textHeight = [text boundingRectWithSize:textRect
                                           options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading
                                        attributes:attributes
                                           context:nil].size.height;
    
    return  textHeight ;
}

相关文章

网友评论

      本文标题:ios中计算文本高度

      本文链接:https://www.haomeiwen.com/subject/pghbuctx.html