Uilabel自动换行 UItableView适应高度

 //设置tableViewcell里uilabel、图片高度
    CGSize tbvContentSizeForheight = [cell.resultNoticeTableContent.text sizeWithFont:cell.resultNoticeTableContent.font];
    CGSize tbvContentSizeForLines = [cell.resultNoticeTableContent.text sizeWithFont:cell.resultNoticeTableContent.font constrainedToSize:CGSizeMake(280, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];
//最大行数
    cell.resultNoticeTableContent.numberOfLines =ceil(tbvContentSizeForLines.height/tbvContentSizeForheight.height);

//自动换行
 if(cell.resultNoticeTableContent.numberOfLines<=1)
 {
 cell.resultNoticeTableContent.frame = CGRectMake(20, 80, 290,30);
 }
 else 
 {
   int tbvHight = cell.resultNoticeTableContent.frame.size.height*cell.resultNoticeTableContent.numberOfLines;
   cell.resultNoticeTableContent.frame = CGRectMake(20, cell.resultNoticeTableContent.frame.origin.y, 290,tbvHight    );
   //cell.resultNoticeImageView.image = [UIImage imageNamed:@"BG.png"];
   cell.resultNoticeImageView.frame = CGRectMake(10, 50, 300, cell.resultNoticeImageView.bounds.size.height+tbvHig    ht-30);
 }
原文地址:https://www.cnblogs.com/qingjoin/p/2663112.html