//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);
时间: 2024-10-09 16:03:57