美文网首页
计算富文本高度不准的坑

计算富文本高度不准的坑

作者: 扶兮摇兮 | 来源:发表于2020-04-21 19:37 被阅读0次
    + (NSAttributedString *)getDescribleContentWithContent:(NSString *)content rateModel:(SHGenerateReportModels *)model{
    
        
    
        NSMutableDictionary *attributesDict = [NSMutableDictionary dictionary];
    
        [attributesDict setValue:[UIFont systemFontOfSize:18.0] forKey:NSFontAttributeName];
    
        [attributesDict setValue:[UIColor colorWithHexString:@"#332532"] forKey:NSForegroundColorAttributeName];
    
        NSMutableParagraphStyle *muParagraph = [[NSMutableParagraphStyle alloc] init];
    
        // 记得设置段落的相关属性
    
        muParagraph.lineBreakMode = NSLineBreakByWordWrapping;
    
        muParagraph.alignment = NSTextAlignmentLeft;
    
        muParagraph.lineSpacing = 10; // 行距
    
        [attributesDict setValue:muParagraph forKey:NSParagraphStyleAttributeName];
    
        NSMutableAttributedString *describeContent = [[NSMutableAttributedString alloc] initWithString:content attributes:attributesDict];
    
        
    
        CGFloat width = [UIScreen mainScreen].bounds.size.width - 96.0;
    
        CGFloat height = [describeContent boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin context:nil].size.height;
    
        // 向上取整 + 1.;
    
        model.describleLabelHeight = ceil(height) + 1.0;
    
        
    
        return describeContent;
    
    }
    

    相关文章

      网友评论

          本文标题:计算富文本高度不准的坑

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