1

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

Muhammad Irfan
  • 1,447
  • 4
  • 26
  • 56

2 Answers2

2

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.

Ozgur Vatansever
  • 49,246
  • 17
  • 84
  • 119
0

Warning from Xcode: 'topLayoutGuide' was deprecated in iOS 11.0: Use view.safeAreaLayoutGuide.topAnchor instead of topLayoutGuide.bottomAnchor

So now you can do this to achieve the same effect.

tableView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 0).isActive = true

Note we use .topAnchor of safeAreaLayoutGuide here.

Daniel Hu
  • 423
  • 4
  • 11