//计算宽度
- (CGFloat)calculateRowWidth:(NSString *)string {
NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:17]};
CGRect rect = [string boundingRectWithSize:CGSizeMake(0, 30) options:NSStringDrawingUsesLineFragmentOrigin |
NSStringDrawingUsesFontLeading attributes:dic context:nil];
return rect.size.width + 5;
}
//计算高度
- (CGFloat)calculateRowHeight:(NSString *)string fontSize:(NSInteger)fontSize{
NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:fontSize]};
CGRect rect = [string boundingRectWithSize:CGSizeMake(self.view.width - 30, 0) options:NSStringDrawingUsesLineFragmentOrigin |
NSStringDrawingUsesFontLeading attributes:dic context:nil];
return rect.size.height;
}
网友评论