tableviewcell 中使用autolayout自适应高度

时间:2023-03-09 17:23:39
tableviewcell 中使用autolayout自适应高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

[cell setNeedsUpdateConstraints];
[cell updateConstraintsIfNeeded];
  CGSize size = [self.prototypeCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
return size.height+1;
}
  • Return the height of the cell remembering to add 1 point for the cell separator.
 cell 中要完全的根据控件之间的属性,可以计算出cell的高度,在使用时,自己可以在图纸上比划一下,根据已知的控件的约束能不能计算出一个cell的高度