Search code examples
iosuinavigationbaruistatusbar

UINavigationBar does not extend behind status bar


I feel like I'm completely overlooking something, since this is so basic.

In a completely bare bones setup:

window = UIWindow(frame: UIScreen.mainScreen().bounds)
window.backgroundColor = UIColor.whiteColor()

let rootController = MainViewController()
rootNavigationController = UINavigationController(rootViewController: rootController)

window.rootViewController = rootNavigationController;
window.makeKeyAndVisible()

// Appearance
UINavigationBar.appearance().barTintColor = UIColor.DailyRate.blueColor
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
UINavigationBar.appearance().opaque = false

I get a navigation bar that does not extend behind the status, which should be default behavior.

enter image description here


Solution

  • It turned out that it was a timing issue.

    The root hierarchy was actually set up in the initializer of a separate class called UIManager. However, this class was initialized at the same time as the AppDelegate

    var uiManager = UIManager()
    

    and not in application(_, didFinishLaunchingWithOptions _) method, thus creating this weird scenario.

    So all I did was

    var uiManager: UIManager?
    
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    
        uiManager = UIManager()
    
    }
    

    And now everything is back to normal.

    Thanks to @govindarao-kondala for planting the right idea in my head!