首页 > 技术文章 > swift 分组tableview 设置分区投或者尾部,隐藏默认间隔高度

qingzZ 2019-02-28 15:39 原文

 

1.隐藏尾部或者头部,配套使用

 


    //注册头部id
        tv.register(JYWithdrawalRecordSectionView.self, forHeaderFooterViewReuseIdentifier: sectionHeaderID)

     //设置高度;注意此处写死的。 如果用VFL 或者自适应,没效果的
       tv.sectionHeaderHeight = 60//但是这里不好获取
    //用下面方法     tv.sectionHeaderHeight = JYWithdrawalRecordSectionView().getLayoutSize().width
    //隐藏尾部 这两行缺一不可, 不然显示默认的20高度的尾部view,隐藏头部同理
     tv.tableFooterView = nil tv.sectionFooterHeight = 0.0001

 

2.显示自定义头部

    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let headerV = tableView.dequeueReusableHeaderFooterView(withIdentifier: sectionHeaderID) as! JYWithdrawalRecordSectionView
        headerV.updataData(data: dataArr[section])
        headerV.clickSection = { [weak self] in
            self?.handleSectionClick(section: section)
        }

        return headerV
    }

  

3.

extension UIView{
    /// 获得一个VFL 或者 layout的控件的size
    func getLayoutSize() -> CGSize{
        self.setNeedsLayout()
        // 立马布局子视图
        self.layoutIfNeeded()
        return self.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)
    }
}

  

 

推荐阅读