當(dāng)UITableView的style為UITableViewStyleGrouped時盾似,發(fā)現(xiàn)第一個cell和頂部留有一定的空白敬辣,tableView的底部也留有一定的空白雪标,大小分別為35pt和20pt。
解決方法
- 想要控制首個cell距離頂部的距離溉跃,可以去控制tableView的偏移量來控制cell的高度:
self.tableView.contentInset = UIEdgeInsetsMake(-35, 0, -20, 0)
- 上面這個方式tableView沒有刷新功能時很簡單實用村刨,在tableView具有下拉和上拉刷新時,這樣的偏移會使得刷新框架的圖標(biāo)也偏移了撰茎,可能被遮擋看不見嵌牺,這個時候可以使用下面的方法:
self.tableView.estimatedSectionHeaderHeight = 0.01;
self.tableView.estimatedSectionFooterHeight = 0.01;
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 0.01;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.01;
}
在iOS15系統(tǒng)上面,plain形式的section和cell之間會存在一個20的間隙龄糊,采用以下方式
if (@available(iOS 15.0, *)) {
[self.tableView setSectionHeaderTopPadding:0.0f];
}
全局修改
if (@available(iOS 15.0, *)) {
[[UITableView appearance] setSectionHeaderTopPadding:0.0f];
}