Jacobo Koenig
Jacobo Koenig

Reputation: 12534

Navigation bar not covering status bar on iPhone X

I have a simple view controller with a view (map) pinned to its superview. The view is embedded on a navigation controller, but the navigation bar starts under the safe area (below status bar) on iPhone X. Ideally, I would like the bar to be under the status bar (not below it), when rendered on an iPhone X. How can I go about doing this?

enter image description here

This is how the bar is being set up to make it semi transparent:

//Design Set Up
let navBar = UINavigationBar.appearance()
navBar.setBackgroundImage(UIImage(), for: .default)
navBar.backgroundColor = UIColor(displayP3Red: 0, green: 0, blue: 0, alpha: 0.5)

Upvotes: 2

Views: 1030

Answers (1)

Paolo
Paolo

Reputation: 3955

You should embed the view controller in a UINavigationController, not use just a UINavigationBar. That way you will automatically get a navigation bar with the navigation controller and it will extend fully to the top of the screen.

https://developer.apple.com/documentation/uikit/uinavigationcontroller

You can add it in a Storyboard or if you're using code, something like:

let mapViewController = UINavigationController(rootViewController: MapViewController())

(assuming your map is called MapViewController)

Upvotes: 1

Related Questions