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;


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

相关文章
|
Swift iOS开发
iOS 用一个布局来解决嵌套问题—— UICollectionViewCompositionalLayout
iOS 用一个布局来解决嵌套问题—— UICollectionViewCompositionalLayout
iOS 用一个布局来解决嵌套问题—— UICollectionViewCompositionalLayout
|
前端开发 开发者
「Mac畅玩鸿蒙与硬件22」鸿蒙UI组件篇12 - Canvas 组件的动态进阶应用
在鸿蒙应用中,Canvas 组件可以实现丰富的动态效果,适合用于动画和实时更新的场景。本篇将介绍如何在 Canvas 中实现动画循环、动态进度条、旋转和缩放动画,以及性能优化策略。
432 6
「Mac畅玩鸿蒙与硬件22」鸿蒙UI组件篇12 - Canvas 组件的动态进阶应用
手势代理 shouldBeRequiredToFailByGestureRecognizer 和 shouldRequireFailureOfGestureRecognizer 的区别
手势代理 shouldBeRequiredToFailByGestureRecognizer 和 shouldRequireFailureOfGestureRecognizer 的区别
558 10
|
缓存 iOS开发
iOS小技能:解决TableVIew刷新数据带来的界面跳动问题
iOS小技能:解决TableVIew刷新数据带来的界面跳动问题
2205 0
iOS小技能:解决TableVIew刷新数据带来的界面跳动问题
|
定位技术 API 开发工具
iOS语言本地化/国际化宝典
iOS语言本地化/国际化宝典
1023 0
iOS语言本地化/国际化宝典
|
安全 关系型数据库 MySQL
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements问题处理
【5月更文挑战第8天】ERROR 1819 (HY000): Your password does not satisfy the current policy requirements问题处理
2520 2
|
Swift iOS开发 UED
【Swift开发专栏】Swift中的动画与过渡效果
【4月更文挑战第30天】本文介绍了Swift中的动画与过渡效果,分为三个部分:动画基础、过渡效果和实战案例。在第一部分,讲解了动画概念,包括UIView动画、动画选项和关键帧动画。第二部分阐述了过渡效果,包括UIView自带的过渡效果和自定义过渡效果。第三部分通过按钮点击动画和页面切换过渡效果展示了实际应用。
421 0
|
监控 iOS开发
iOS15适配问题:viewForSupplementaryElementOfKind表头和表尾复用闪退,UITableView section header多22像素等问题
iOS15适配问题:viewForSupplementaryElementOfKind表头和表尾复用闪退,UITableView section header多22像素等问题
495 0
element-ui 表格和 tooltip修改背景颜色和箭头颜色
element-ui 表格和 tooltip修改背景颜色和箭头颜色
2032 0

热门文章

最新文章