用字符串的内容,Label的宽度和字体的大小,可自动计算所需出Label高度
+ (CGFloat)heightWithString:(NSString *)text withWidth:(CGFloat)width withFontSize:(CGFloat)fontSize {
CGSize textSize = CGSizeMake(width, 0);
NSDictionary *font = @{NSFontAttributeName : [UIFont systemFontOfSize:fontSize]};
CGRect rect = [text boundingRectWithSize:textSize options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:font context:nil];
return rect.size.height;
}
网友评论