UITableView .grouped 类型去除顶部间距

在设置 UITableView 的 style 为 .grouped 类型的时候,发现第一个 cell 的顶部存在大段的间距,而改成 .plain 类型则没有这个间距,效果以下:spa

设置了 contentInset 和 heightForHeader 为 0.01 都无效,最后发现是 代理

tableView.tableFooterView = UIView()

的书写位置有问题,只要调整代码的顺序就能够了,以下:code

调整后再看效果就正常了:blog

对应代理中 heightForHeader 和 heightForFooter 的设置以下:get

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { return 10 } func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { return 10 }

 

【参考】UITableViewStyleGrouped模式下烦人的多余间距io

 

相关文章
相关标签/搜索