UITableView.Style plain grouped

本文详细介绍了UITableView的两种风格:plain和grouped,并提供了消除间隔、设置区头区尾高度的方法,以及如何实现多段头停留的效果。通过代理方法调整内容留白,创建无缝隙的表格展示,同时讲解了如何自定义UITableView的表头、区头、区尾和表尾视图。
摘要由CSDN通过智能技术生成
  1. style
    UITableView 的展示方式
//表头
tableView.tableHeaderView 
//区头
	func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 0.001
    } 
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        return UIView()
    }
    
    //cell 内容
    
    //区尾
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.001
    } 
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        return UIView()
    }
    //表尾
    tableView.tableFooterView

UITableView.Style.plain

  1. 有多段时 段头停留(自带效果)

  2. 没有中间的间距和头部间距(要想有的重写 UITableViewCell \UITableViewHeaderFooterView 里面的 setFrame 方法)

UITableView.Style.grouped

  1. 设置表头的高度为特小值 (不能为零 为零的话苹果会取默认值就无法消除头部间距了)

  2. 写代理方法(中间的留白其实是段尾的高度 代理的作用设置段尾的高度 返回值也不能为 0)

 	func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 0.001
    } 
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        return UIView()
    }
     func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.001
    } 
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        return UIView()
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值