第一种方法:通过代理设置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;
如果同时也设置代理,那将会以代理的高度为标准
网友评论