How to change height of grouped UITableView header?

前端 未结 10 729
野性不改
野性不改 2020-12-07 09:22

I know how to change the height of the section headers in the table view. But I am unable to find any solution to change the default spacing before the first section.

10条回答
  •  孤城傲影
    2020-12-07 10:25

    In Swift 4

    Remove extra top padding in grouped tableview.

    Here height is given 1 as minimal height for the section header because you cannot give 0 as tableview will take it default top margin if assigned zero height.

    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 1
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        return UIView()
    }
    

提交回复
热议问题