- (CGFloat)heightWithText:(NSString *)text font:(UIFont*)font width:(CGFloat)width;
- (CGFloat)heightWithFontSize:(CGFloat)size width:(CGFloat)width;
- (CGFloat)heightWithText:(NSString *)text font:(UIFont *)font width:(CGFloat)width{
NSDictionary *attributes = @{NSFontAttributeName:font};
CGSize contentSize = [text boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) attributes:attributes context:nil].size;
return contentSize.height;
}
-(CGFloat)heightWithFontSize:(CGFloat)size width:(CGFloat)width{
NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:size]};
CGSize contentSize = [self boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) attributes:attributes context:nil].size;
return contentSize.height;
}
网友评论