chikwong yip
chikwong yip

Reputation: 3

How to set tableViewHeader

I am working on menu bar using SWReveaViewController, I did it, Now I change the uitableview'tableHeaderView(not section header view) , But the result not my expect, Why it had a seperator space on the top my tableview, I think it section header? But I don't know how to change it, Please help.... here it is my result

My code:

 let headerView = UIView(frame:CGRect(x:0,y:0,width:self.view.frame.width,height:40))
        headerView.backgroundColor = UIColor(red: 47/225, green: 97/225, blue: 76/225, alpha: 1)
        self.tableView.tableHeaderView = headerView

Upvotes: 0

Views: 148

Answers (2)

RajeshKumar R
RajeshKumar R

Reputation: 15748

The top space above the header is safe area insets. You should change your table view top anchor to its superview.

In storyboard you need to change the top constraint of the tableview. In storyboard select the tableview and select size inspector.

enter image description here

Select the top constraint by double clicking. And change the second item from Safe Area to Superview then change the constant value to 0.

enter image description here enter image description here

And use

if #available(iOS 11.0, *) {
    self.tableView.contentInsetAdjustmentBehavior = .never
} else {
    automaticallyAdjustsScrollViewInsets = false
}

Upvotes: 1

A. Amini
A. Amini

Reputation: 561

Try this:

    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 0
    }

Upvotes: 0

Related Questions