- 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
-
有多段时 段头停留(自带效果)
-
没有中间的间距和头部间距(要想有的重写 UITableViewCell \UITableViewHeaderFooterView 里面的 setFrame 方法)
UITableView.Style.grouped
-
设置表头的高度为特小值 (不能为零 为零的话苹果会取默认值就无法消除头部间距了)
-
写代理方法(中间的留白其实是段尾的高度 代理的作用设置段尾的高度 返回值也不能为 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()
}