Arunabh Das
Arunabh Das

Reputation: 14392

StatusBarStyle not working as expected on iOS 9

I am trying to get the following StatusBarStyle on my swift app :

enter image description here

My AppDelegate uses a UINavigationController as follows

self.nav = UINavigationController(rootViewController: controller!)

So I tried to set the UIBarStyle to Black as follows :

    self.nav?.navigationBar.barStyle = UIBarStyle.Black

However, this results in the following :

enter image description here

BTW, on my Info.plist, I have the following set

<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleDefault</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

And those settings result in the desired statusbar style on the LaunchScreen but not on the other screens.

I even tried adding the following method to all the VCs inside the UINavigationController

override func preferredStatusBarStyle() -> UIStatusBarStyle {
    return UIStatusBarStyle.Default
}

But that results in the following status bar style :

enter image description here

What is the best way to have the desired status bar style in the case where you have a UINavigationController on iOS 9?

Additionally, if I remove the plist entry and set

 self.nav?.navigationBar.barStyle = UIBarStyle.Black 

in AppDelegate, I get the following result :

white_text_on_gray_background_status_bar_style

Additionally, I removed all the places where backgroundColor was being set except the following in AppDelegate (colorOne is the deepBlue color I want on the status bar)

self.window?.backgroundColor = colorOne

And when I did this, I get a light blue color on the status bar, which is the closest color to the deep blue color I need on the status bar as seen here

black_text_on_light_blue_status_bar

Upvotes: 1

Views: 728

Answers (2)

Akash Raghani
Akash Raghani

Reputation: 557

i hope this may help you..

if you need a specific color, how you do it with RGB is the best option:

  UINavigationBar.appearance().barTintColor = UIColor(red: 5.0, green: 8.0, blue: 9.0, alpha:0.5) 

if its not working then try this: var navigationBarAppearace = UINavigationBar.appearance()

    navigationBarAppearace.tintColor = UIColor.whiteColor()
    navigationBarAppearace.barTintColor = UIColor(red:15/255.0, green:  167/255.0, blue: 216/255.0, alpha: 1.0)

Upvotes: 0

Dimitrios Kalaitzidis
Dimitrios Kalaitzidis

Reputation: 181

In appDelegate use:

  UINavigationBar.appearance().barTintColor = UIColor.redColor()
  UINavigationBar.appearance().translucent = false

Obviously you can use any UIColor you want...

Upvotes: 4

Related Questions