; } iOS8以上(包含iOS8) 添加一下两个属性就行了 self.tableView.estimatedRowHeight = 44.0; self.tableView.rowHeight = UITableViewAutomaticDimension 试了好久终于找到了解决方法 假如UITableViewCell中就放一个view 设置该view以下约束 宽度和高度(假设为宽100 高100) 水平居中 距离顶部距离(=10) 距离底部距离(>=10) 这样设置之后UITableViewAutomaticDimension
disable": @available(iOS 7.0, *) open var estimatedSectionHeaderHeight: CGFloat // default is UITableViewAutomaticDimension disable @available(iOS 7.0, *) open var estimatedSectionFooterHeight: CGFloat // default is UITableViewAutomaticDimension
设置tableViewCell的真实行高和估算行高 // 告诉tableView所有cell的真实高度是自动计算(根据设置的约束来计算) self.tableView.rowHeight = UITableViewAutomaticDimension
CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewAutomaticDimension ; } 实现中针对某个cell返回一个特定高度值UITableViewAutomaticDimension。 CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewAutomaticDimension ; } 实现中针对某个cell返回一个特定高度值UITableViewAutomaticDimension。
UITableView类中还有一个十分有趣的常量: UIKIT_EXTERN const CGFloat UITableViewAutomaticDimension; UITableViewAutomaticDimension UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ //视图为nil则会自动返回0 return UITableViewAutomaticDimension
height = [_cellHeightsDic objectForKey:indexPath]; if (height) return height.doubleValue; return UITableViewAutomaticDimension
0; self.tableView.estimatedSectionFooterHeight = 0; 还可以这样设置 //cell自适应高度 self.tableView.rowHeight = UITableViewAutomaticDimension
这时候回想起来UITableView有一个estimatedRowHeight属性,查了一下这个属性的说明,发现默认值是UITableViewAutomaticDimension(-1)表示不会预估高度 所以iOS7的时候UIKit引入了estimatedRowHeight,并且为了兼容旧代码设置默认值是UITableViewAutomaticDimension。
具体可以参考UIBarAppearance 2、tableView 增加sectionHeaderTopPadding属性,默认值是UITableViewAutomaticDimension,可能会使tableView
Self-Sizing在iOS11下是默认开启的,Headers, footers, and cells都默认开启Self-Sizing,所有estimated 高度默认值从iOS11之前的 0 改变为UITableViewAutomaticDimension : @property (nonatomic) CGFloat estimatedRowHeight NS_AVAILABLE_IOS(7_0); // default is UITableViewAutomaticDimension estimateRowHeight的值,也没有设置rowHeight的值,那contentSize计算初始值是 44 x cell的个数,如下图:rowHeight和estimateRowHeight都是默认值UITableViewAutomaticDimension
指定rowHeight属性为 automatic dimension self.tabelView.rowHeight = UITableViewAutomaticDimension; // -----
tmpView; _tableView.bounces = NO; tmpView.delegate = self; tmpView.rowHeight = UITableViewAutomaticDimension
UITableView iOS15对于tableview,新增了sectionHeaderTopPadding作为列表每个部分标题上方的填充,它的默认值是UITableViewAutomaticDimension
AutomaticDimension: 该解决方案对应着,下方第一个Cell, 点击该Cell进入的页面完全由AutoLayout进行布局,Cell自适应的高度也不用我们自己计算,而是使用系统提供的解决方案UITableViewAutomaticDimension 当然,使用UITableViewAutomaticDimension要依赖于你添加的约束,稍后会介绍到。这种实现方案用起来简单,不过UI流畅度方面不太理想。 下方就是我们添加完约束后要做的事情,需要给我们的tableView设置一个预估值(estimatedRowHeight), 然后在TableViewDelegate的heightForRowAtIndexPath方法中返回UITableViewAutomaticDimension
// self-sizing self.tableView.estimatedRowHeight = 200.f; self.tableView.rowHeight = UITableViewAutomaticDimension
vauleLabel的宽度 随 keyLabel的宽度自适应,valueLabel的高度 随 内容自适应,cell的高度随内容自适应~ 小tips-->如果设置完_tableView.rowHeight=UITableViewAutomaticDimension
Self-Sizing在iOS11下是默认开启的,Headers, footers, and cells都默认开启Self-Sizing,所有estimated 高度默认值从iOS11之前的 0 改变为UITableViewAutomaticDimension estimateRowHeight的值,也没有设置rowHeight的值,那contentSize计算初始值是 44 cell的个数,如下图:rowHeight和estimateRowHeight都是默认值UITableViewAutomaticDimension
最好给contentView设置"顶部"底部"及宽度约束 3.2 具体实施 3.2.1 添加预估行高、自行计算行高 //预估行高 //自动计算行高 self.tableView.rowHeight = UITableVIewAutomaticDimension
Self-Sizing在iOS11下是默认开启的,Headers, footers, and cells都默认开启Self-Sizing,所有estimated 高度默认值从iOS11之前的 0 改变为UITableViewAutomaticDimension estimateRowHeight的值,也没有设置rowHeight的值,那contentSize计算初始值是 44 * cell的个数,如下图:rowHeight和estimateRowHeight都是默认值UITableViewAutomaticDimension
开启了自动估算行高,estimatedRowHeight``estimatedSectionHeaderHeight estimatedSectionFooterHeight三个高度估算属性由默认的0变成了UITableViewAutomaticDimension viewForHeaderInSection:,那么estimatedRowHeight estimatedSectionHeaderHeight estimatedSectionFooterHeight三个高度估算属性由默认的0变成了UITableViewAutomaticDimension