传内容string和字体大小,就可以计算多少行。
-(CGFloat)getLineNum:(NSString*)str font:(UIFont*)font labelWidth:(CGFloat)width
{
if (str.length<1)
{
return 0;
}
CGFloat oneRowHeight = [@"占位" sizeWithAttributes:@{NSFontAttributeName:font}].height;
CGSize textSize = [str boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil].size;
CGFloat rows = textSize.height / oneRowHeight;
return rows;
}