IOS - UITableView - headerView自适应

xiaoxiao2021-02-28  76

网上的headerview自适应比较复杂,贡献出简单又有效的headerView的自适应方法:

1.一个充分约束的视图View(作为headerView)

意思就是,他里边的约束要和父view完全关联起来,不存在冲突,或者多参考。 该view依赖Viewcontroller,结构如下:

2.添加如下代码:

func tableView(_ tableView: UITableView, estimatedHeightForHeaderInSection section: Int) -> CGFloat { return headerView.frame.size.height; } func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { return headerView }

3.如果你没成功,请仔细阅读

转载请注明原文地址: https://www.6miu.com/read-85577.html

最新回复(0)