可以寫成一個(gè)類方法
pragma mark ---計(jì)算文本的高度
+(CGFloat)hightFromText:(NSString *)textStr width:(CGFloat)width
{
//計(jì)算文本的高度
CGSize constraintSize;
constraintSize.width = width;
constraintSize.height = MAXFLOAT;
CGSize sizeFrame = [textStr boundingRectWithSize:constraintSize options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:15.0],NSFontAttributeName, nil] context:nil].size;
//重新調(diào)整contentView.PenContent的高度
CGFloat high = sizeFrame.height+5.0;
return high;
}