//自定义高度
//
导致计算不准确
:
//1. 限定的宽度和 lable 的宽度不一致
//2. 计算时使用的字体及字号与 lable 显示时使用的字体和字号不一致
NSDictionary * dic = [ NSDictionary dictionaryWithObjectsAndKeys :[ UIFont systemFontOfSize : 12 ], NSFontAttributeName , nil ];
// 第一个参数 : 宽度 和 lable 一样 , 高度要么不设 ( 为 0), 要么就足够大 , 否则都会导致计算错误
// 第二个参数 : 是从原点开始绘制
// 第三个参数 : 是文本绘制所需的属性 , 如 : 字号 等
CGRect rect = [str boundingRectWithSize : CGSizeMake ( 280 , 0 ) options :( NSStringDrawingUsesLineFragmentOrigin ) attributes :dic context : nil ];
//NSLog(@"%@", NSStringFromCGRect(rect));
aLable. frame = CGRectMake (aLable. frame . origin . x , aLable. frame . origin . y , aLable. frame . size . width , rect. size . height );
//1. 限定的宽度和 lable 的宽度不一致
//2. 计算时使用的字体及字号与 lable 显示时使用的字体和字号不一致
NSDictionary * dic = [ NSDictionary dictionaryWithObjectsAndKeys :[ UIFont systemFontOfSize : 12 ], NSFontAttributeName , nil ];
// 第一个参数 : 宽度 和 lable 一样 , 高度要么不设 ( 为 0), 要么就足够大 , 否则都会导致计算错误
// 第二个参数 : 是从原点开始绘制
// 第三个参数 : 是文本绘制所需的属性 , 如 : 字号 等
CGRect rect = [str boundingRectWithSize : CGSizeMake ( 280 , 0 ) options :( NSStringDrawingUsesLineFragmentOrigin ) attributes :dic context : nil ];
//NSLog(@"%@", NSStringFromCGRect(rect));
aLable. frame = CGRectMake (aLable. frame . origin . x , aLable. frame . origin . y , aLable. frame . size . width , rect. size . height );
6.0 计算字符串高度
CGSize rect = [lab sizeWithFont:[UIFont systemFontOfSize:12] constrainedToSize:CGSizeMake(280,2000) lineBreakMode:NSLineBreakByTruncatingHead];
7.0 计算字符串高度
CGRect rect = [str boundingRectWithSize:CGSizeMake(300, 800) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:Nil];