根据fontSize计算String的size的高度可以由以下方法:
+(CGFloat)getHeightSizeFromString:(NSString *)myString Font:(UIFont *)myFont Width:(float)myWidth {
NSMutableAttributedString* attributedText = [[NSMutableAttributedString alloc]initWithString:myString];
[attributedText addAttribute:NSFontAttributeName value:myFont
range:NSMakeRange(0, [attributedText length])];
NSStringDrawingOptions options = NSStringDrawingUsesLineFragmentOrigin |
NSStringDrawingUsesFontLeading;
CGRect boundingRect = [attributedText boundingRectWithSize:CGSizeMake(myWidth, CGFLOAT_MAX)
options:options
context:nil];
return ceil(boundingRect.size.height);
}
这个时候UILable的多行设置则为:
NSString* str1 = @“