NSDictionary *fontDict = @{NSFontAttributeName:[UIFont systemFontOfSize:12]};
CGRect rect = [_titleLbl.text boundingRectWithSize:CGSizeMake(200, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:fontDict context:nil];
// 比如想获取高度一定要用ceilf函数
CGFloat titleHeight = ceilf(rect.size.height);
//如果直接CGFloat titleHeight = rect.size.height;发现不换行
网友评论