动态计算Label高度

//1.设置该label的numberOfLines为0
self.titleLabel.numberOfLines = 0;
  
//2.字体的设置要与之前相同
NSDictionary * attribute = @{NSFontAttributeName:[UIFont systemFontOfSize:17]};
 
//3.将size的高度设为最大值
CGSize size = CGSizeMake(355, CGFLOAT_MAX);
 
//4.将label的高度设为动态计算出的size的高度
size = [news.title boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:attribute context:nil].size;
   
self.titleLabel.frame = CGRectMake(10, 0, 355, size.height);
 

posted on 2016-03-21 11:19  sea_star3  阅读(223)  评论(0编辑  收藏  举报

导航