ios计算内容的高度 (含7.0前及以后的版本的用法)

+ (CGFloat)heightForContent:(MyMsgTextModel *)content withWidth:(CGFloat)width

{

    CGSize contentSize;

    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {

        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];

        paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;

        NSDictionary *attributes = @{NSFontAttributeName:CELL_CONTENT_FONT_SIZE};

        

        contentSize = [content.textMsg boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size;

    }

    else{

        contentSize = [content.textMsg sizeWithFont:CELL_CONTENT_FONT_SIZE constrainedToSize:CGSizeMake(width, CGFLOAT_MAX) lineBreakMode:NSLineBreakByWordWrapping];

    }

    return contentSize.height;

}

原文地址:https://www.cnblogs.com/NSong/p/5424932.html