swift - 使用 .grouped tableview 时,摆脱在我的标题中添加的空间
问题描述
我制作了 tableview .grouped ,这样标题就不会粘了。但是,这会导致在 tableview 的顶部和底部添加额外的填充(我已修复),以及在我的标题视图顶部添加额外的空间。在网上,似乎人们唯一在谈论的是摆脱标题,但标题是我将它分组的原因,因为这样可以防止它粘住。如何摆脱 .grouped 添加到所有标题的 20 左右像素的填充而不摆脱我的标题视图?撤消 .grouped 设置会消除空白。这是我想保持分组的唯一方法吗?
你会认为苹果会让这件事变得更容易。
我将标题涂成红色以突出上面不需要的空白。更改单元格所在行的高度不会影响白色区域。
解决方案
这将摆脱整个 tableView 的 headerView 和 footerView:
tableView.tableHeaderView = UIView(frame: CGRect(x: CGFloat.leastNonzeroMagnitude, y: CGFloat.leastNonzeroMagnitude, width: tableView.bounds.size.width, height: CGFloat.leastNonzeroMagnitude))
tableView.tableFooterView = UIView(frame: CGRect(x: CGFloat.leastNonzeroMagnitude, y: CGFloat.leastNonzeroMagnitude, width: tableView.bounds.size.width, height: CGFloat.leastNonzeroMagnitude))
然后要单独将节标题的高度设置为 0,您必须使用以下函数:
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return CGFloat.leastNonzeroMagnitude
}
对于每个部分的页脚,类似地:
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return CGFloat.leastNonzeroMagnitude
}
推荐阅读
- jenkins - Jenkins 高级下拉参数
- highcharts - 提升面积图使其看起来像条形图
- javascript - d3 js onclicknode函数只返回id元素
- html - TinyMCE 使用“粘贴”插件将 alpha 列表转换为复制/粘贴时的编号列表
- typescript - 打字稿不能根据可选属性缩小联合
- javascript - 如何更新reactjs中的对象数组
- javascript - MS Edge api 错误“未定义浏览器”
- multithreading - 用户空间调度困境中的线程
- java - 从源代码自动生成 Java .class 文件的最安全方法,独立于构建环境
- git - git history 是否会破坏使用 OpenSSL 加密的文件?