iosuitableviewswift3statusbaruitableviewsectionheader

how can i take uitableview header behind status bar?


I have added two images, first one shows what i want and second one shows what is happening. I want uitableview header to go behind the status bar as shown in first image. deployment target is 9.2

enter image description here

and second one is

enter image description here


Solution

  • I assume you are using Autolayout so you can either constraint tableView's .top margin to its super view's .top or view controller's topLayoutGuide property so that the table view will start from 0:

    let toItem: Any = self.topLayoutGuide 
    // You can change this to `self.view` to have the same effect. 
    
    view.addConstraint(
      NSLayoutConstraint(item: tableView, 
        attribute: NSLayoutAttribute.top, 
        relatedBy: NSLayoutRelation.equal, 
        toItem: toItem, 
        attribute: NSLayoutAttribute.top, 
        multiplier: 1.0, constant: 0
      )
    )
    

    Here is how it looks in my simulator:

    enter image description here

    To have the table header start below the status bar, just use layoutGuide's .bottom property instead of .top:

    enter image description here

    Here you can download the test project.