UITableViewStyleGrouped模式下烦人的多余间距

简介: UITableViewStyleGrouped模式下烦人的多余间距

第一种方法:通过代理设置head和foot的高度

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let view = UIView(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: 20))
        view.backgroundColor = UIColor.gray
        return view
    }
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        return nil
    }
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 20
    }
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        if section == 3 {
            return 50
        }
        return 0.01
    }


注意:只设置高度是没效果的


func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 20
    }
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        if section == 3 {
            return 50
        }
        return 0.01
    }


第二种方法:直接设置 无需设置代理

tableView.sectionFooterHeight = 0;
        tableView.sectionHeaderHeight = 10;


如果同时也设置代理,那将会以代理的高度为标准

相关文章
|
19天前
VSCode如何自动换行,右侧换行间距长度,隐藏右侧代码预览(Minimap代码缩略图滚动条),比对代码差异窗口也自动换行
VSCode如何自动换行,右侧换行间距长度,隐藏右侧代码预览(Minimap代码缩略图滚动条),比对代码差异窗口也自动换行
多行文本溢出省略号击展开收缩(整理)
多行文本溢出省略号击展开收缩(整理)
OFFICE技术讲座:设置调整字间距(kern/kerning)后,标点就不压缩
OFFICE技术讲座:设置调整字间距(kern/kerning)后,标点就不压缩
145 0
OFFICE技术讲座:设置调整字间距(kern/kerning)后,标点就不压缩
|
算法 Java 测试技术
常见重构技巧 - 去除多余的if else
常见重构技巧 - 去除多余的if else
常见重构技巧 - 去除多余的if else
|
iOS开发
iOS开发-调整文字之间间距
iOS开发-调整文字之间间距
250 0
OFFICE技术讲座:设置调整字间距(kern)后,标点就不压缩
OFFICE技术讲座:设置调整字间距(kern)后,标点就不压缩
144 0
OFFICE技术讲座:设置调整字间距(kern)后,标点就不压缩
一个脚本教你快速去除桌面图标烦人的小箭头!!
一个脚本教你快速去除桌面图标烦人的小箭头!!
707 0