當(dāng)UITableView的style為UITableViewStyleGrouped時(shí),發(fā)現(xiàn)第一個(gè)cell和頂部留有一定的空白,tableView的底部也留有一定的空白,大小分別為35pt和20pt。
解決方法
- 想要控制首個(gè)cell距離頂部的距離,可以去控制tableView的偏移量來(lái)控制cell的高度:
self.tableView.contentInset = UIEdgeInsetsMake(-35, 0, -20, 0)
- 上面這個(gè)方式tableView沒(méi)有刷新功能時(shí)很簡(jiǎn)單實(shí)用,在tableView具有下拉和上拉刷新時(shí),這樣的偏移會(huì)使得刷新框架的圖標(biāo)也偏移了,可能被遮擋看不見(jiàn),這個(gè)時(shí)候可以使用下面的方法:
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之間會(huì)存在一個(gè)20的間隙,采用以下方式
if (@available(iOS 15.0, *)) {
[self.tableView setSectionHeaderTopPadding:0.0f];
}
全局修改
if (@available(iOS 15.0, *)) {
[[UITableView appearance] setSectionHeaderTopPadding:0.0f];
}