RankoR RankoR - 3 months ago 12
iOS Question

View doesn't go under status bar and status bar is black

I'm hiding the Navigation Bar on one of the screens, and if is set:

navigationController?.navigationBarHidden = true


The status bar becomes black. Also, the image doesn't fit all the screen (see the screenshot).
If I comment this line, Navigation bar stays on screen, and the status bar is white.

Full code:

override func viewWillAppear(animated: Bool) {
navigationController?.navigationBarHidden = true
navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
navigationController?.navigationBar.translucent = true
navigationController?.navigationBar.backgroundColor = UIColor.clearColor()
navigationController?.view.backgroundColor = UIColor.clearColor()


enter image description here

All constraints of ImageView are set to 0 and it's set to fill the screen:

enter image description here

So, I want to put ImageView under the status bar and make the status bar icons/text white. What I'm doing wrong?

Answer

You're not doing anything "wrong". You have set the top of the image view to the bottom of the view controller's top layout guide. Well, that's the bottom of the status bar — exactly where you see the top of the image view.

If you want the image view to underlap the status bar, its top needs to be pinned to the top of the main view, not the top layout guide.

And if you want the status bar to change text color, you need to implement preferredStatusBarStyle to return .LightContent. If this means that the result of preferredStatusBarStyle has changed, you would need to call setNeedsStatusBarAppearanceUpdate to alert the runtime to this fact.

Comments