美文网首页
解决TableView类型为group顶部和底部留有空白问题

解决TableView类型为group顶部和底部留有空白问题

作者: 小盟城主 | 来源:发表于2020-01-07 14:46 被阅读0次

当UITableView的style为UITableViewStyleGrouped时,发现第一个cell和顶部留有一定的空白,tableView的底部也留有一定的空白,大小分别为35pt和20pt。

解决方法

  1. 想要控制首个cell距离顶部的距离,可以去控制tableView的偏移量来控制cell的高度:
self.tableView.contentInset = UIEdgeInsetsMake(-35, 0, -20, 0)
  1. 上面这个方式tableView没有刷新功能时很简单实用,在tableView具有下拉和上拉刷新时,这样的偏移会使得刷新框架的图标也偏移了,可能被遮挡看不见,这个时候可以使用下面的方法:
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系统上面,plain形式的section和cell之间会存在一个20的间隙,采用以下方式

if (@available(iOS 15.0, *)) {
     [self.tableView setSectionHeaderTopPadding:0.0f]; 
}

全局修改

if (@available(iOS 15.0, *)) {
    [[UITableView appearance] setSectionHeaderTopPadding:0.0f]; 
}

相关文章

网友评论

      本文标题:解决TableView类型为group顶部和底部留有空白问题

      本文链接:https://www.haomeiwen.com/subject/clyractx.html