iOS 计算字符串高度

- (CGSize)boundingRectWithSize:(CGSize)size
{
    NSDictionary *attribute = @{NSFontAttributeName: self.font};

    CGSize retSize = [self.text boundingRectWithSize:size
                                             options:
                      NSStringDrawingUsesLineFragmentOrigin |
                      NSStringDrawingUsesFontLeading
                                          attributes:attribute
                                             context:nil].size;

    return retSize;
}

你可能感兴趣的:(iOS 计算字符串高度)