美文网首页
UILabel 设置行高后计算内容高度

UILabel 设置行高后计算内容高度

作者: 114105lijia | 来源:发表于2019-06-14 10:41 被阅读0次

    UILabel设置行高:

    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text];
    NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStylesetLineSpacing:8];
            [attributedStringaddAttribute:NSParagraphStyleAttributeNamevalue:paragraphStylerange:NSMakeRange(0, [textlength])];
    [_footLabsetAttributedText:attributedString];
    

    计算内容高度:

    NSDictionary *d = @{NSParagraphStyleAttributeName: paragraphStyle,NSFontAttributeName: [UIFont systemFontOfSize:15]};
    CGRect rect = [text boundingRectWithSize:CGSizeMake(MAINSCREEN_WIDTH, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:d context:nil];
    CGFloat h = ceilf(rect.size.height);
    

    相关文章

      网友评论

          本文标题:UILabel 设置行高后计算内容高度

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