Simon Simon - 3 months ago 20
iOS Question

iOS Custom Status Bar Background Color not displaying

I am trying to fill the status bar background color to orange using the following

UINavigationBar.appearance().tintColor = UIColor.orangeColor()
UINavigationBar.appearance().barTintColor = UIColor.orangeColor()
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: true)


However, I get a white status bar that should be filled with orange instead from following this example: https://coderwall.com/p/dyqrfa/customize-navigation-bar-appearance-with-swift

I am setting this up in the AppDelegate.swift file under didFinishLaunchingWithOptions method to apply it to the entire app.

I have edited my info.plist to the following:
View controller-based status bar appearance => NO


Does anyone know what I am doing wrong?

Edit: I'm not sure if it matters but the view is in a UITabBarController

Edit 2: This is happening in all the views actually, not just the UITabBarController.

Edit 3: Thanks @Utsav Parikh

I am adding a view now on top of the status bar and it for a brief moment while the app loads the status bar is orange but, once it finishes loading it gets pushed OFF the view and replaced with the generic white status bar.
Why would this be happening?

let view = UIView(frame: CGRect(x: 0.0, y: 0.0, width: UIScreen.mainScreen().bounds.size.width, height: 20.0))
view.backgroundColor=UIColor.orangeColor()
self.window!.rootViewController!.view.addSubview(view)

Answer

Thanks to @Utsav I added the following subview to my UITabBarController and this seems to be working now:

    let view = UIView(frame:
                    CGRect(x: 0.0, y: 0.0, width: UIScreen.mainScreen().bounds.size.width, height: 20.0)
                )
    view.backgroundColor = UIColor.orangeColor()

    self.view.addSubview(view)

The UITabBarController doesn't seem to play well in AppDelegate. If anyone has a better way let me know but, as of now this is the solution I have come around to.