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;
}
}
热门推荐
5 敏字的祝福语简短
10 感动妈妈的祝福语简短
11 年后祝福语简短走心
12 初八的祝福语简短
13 哥哥新婚祝福语创意简短
14 古风婚礼祝福语唯美简短
15 老师简短祝福语有哪些
16 毕业祝福语给同学 简短
17 送花祝福语简短十一朵
18 给红包祝福语简短搞笑