iOS8新特性 计算 cell 的高度

http://tutuge.me/2015/08/08/autolayout-example-with-masonry2/

1.tableview:

 自动计算 tableVIew 的 cell 的高度:

 1. 创建 tableview 的时候:

        tableview.rowHeight = UITableViewAutomaticDimension;(自动获取 cell 的高度)

 2. 在heightForRowAtIndexPath: 方法中直接返回:UITableViewAutomaticDimension 即可. 

 

#define IOS8_TARGET


#ifdef IOS8_TARGET

// 这里做判断 大于 ios8的时候要做的事放在里面


#endif

 

iOS 8之前的计算方式:

[cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height + 0.5; 

 [_templateCell.contentViewsystemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height + 0.5f  

原文地址:https://www.cnblogs.com/Flysouler-1001/p/5239326.html