systemLayoutSizeFittingSize计算cel

2016-07-21  本文已影响640人  petter102

这是搜索到的原文

1、在Cell对应的xib文件中建立完整的约束。

2、使用

   [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize]
我的理解就是通过autolayout使用这个方法自动计算出cell的高度

方法对cell进行动态计算高度,然后在

  - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

返回cell的高度。

注意:

[cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize]

一定是cell.contentView,不能用cell。

最后附上代码地址

上一篇 下一篇

猜你喜欢

热点阅读