根据NSString知道文本的高度或者宽度
2016-07-21 本文已影响138人
rztime
/**
* 根据content的内容,设置cell的动态高度
*
* @param content
*
* @return <#return value description#>
*/
+ (CGFloat)getHeightWithContent:(NSString *)content
{
// 计算文本高度
UIFont *fnt = [UIFont systemFontOfSize:15]; // 文字的size
CGRect tmpRect = [content boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width - 40, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys:fnt,NSFontAttributeName, nil] context:nil];// [UIScreen mainScreen].bounds.size.width - 40 设置最大显示的宽度
CGFloat textheight = tmpRect.size.height;
return textheight; // 文本的高度
}