美文网首页
TTTAttributedLabel 高度计算

TTTAttributedLabel 高度计算

作者: 赵琛 | 来源:发表于2016-10-24 18:18 被阅读943次
    1.TTTAttributedLabel里的文字高度计算和普通label的动态高度不同,如果你用普通label的动态高度计算的话,在TTTAttributedLabel里则显示不对
    2.下面方法
    // tttLabel是TTTAttributedLabel的实例
    // _model.content是NSString实例
    
    __block CGFloat height = 0;
    [self. tttLabel setText:_model.content afterInheritingLabelAttributesAndConfiguringWithBlock:^NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString) {
    height = [TTTAttributedLabel sizeThatFitsAttributedString:mutableAttributedString
    withConstraints:CGSizeMake(200, MAXFLOAT)
    limitedToNumberOfLines:0].height;
    return mutableAttributedString;
    }];
    NSLog(@"%f",height);
    

    相关文章

      网友评论

          本文标题:TTTAttributedLabel 高度计算

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