根据字符串宽度算高度

- (CGFloat)heightForBoundingWidth:(CGFloat)width font:(UIFont *)font
{
    NSAttributedString *attributedSelf = [[NSAttributedString alloc] initWithString:self attributes:@{ NSFontAttributeName:font }];
    return [attributedSelf boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin context:nil].size.height;
}

你可能感兴趣的:(根据字符串宽度算高度)