iOS 自定格单元
示例
苹果在iOS8中引入了自动调整大小单元。使用Autolayout显式地布局UITableViewCells,UITableView会为您处理其余的工作。行高是自动计算的,默认rowHeight值为UITableViewAutomaticDimension。
estimatedRowHeight自调整单元格计算时使用UITableView属性。
创建自调整大小的表格视图单元格时,需要设置此属性并使用约束来定义单元格的大小。
-苹果的UITableView文档
self.tableView.estimatedRowHeight = 44.0
请注意,如果要为所有单元格设置动态高度,heightForRowAtIndexPath则不需要tableView的委托。在必要时以及重新加载或加载表格视图之前,只需设置以上属性即可。但是,您可以通过以下功能设置特定单元格的高度,同时使其他单元格动态化:
迅速
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
switchindexPath.section{
case 1:
return 60
default:
return UITableViewAutomaticDimension
}
}目标C
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.section) {
case 1:
return 60;
default:
return UITableViewAutomaticDimension;
}
}
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短