0

I have a tabBarApp,

the 1 tab is a NavigationController and include the status bar

the 2 is a simple viewCOntroller where I added a NavigationBar ( it include the status bar)

the 3 tab doesn't have a status bar

I changed my Plist file to viewControllerBasedStatusBarAppearence to YES because I need each tab to have a different handling with the status bar ( the 1st and 2nd tab must have it, but the 3rd must have it hidden )

I wrote this inside the first two controllers...

override funct preferredStatusBarStyle() -> UIStatusBarStyle { return UIStatusBarStyle.LightContent }

override func prefersStatusBarHidden() -> Bool {    return false  }

and I wrote this inside the third controller

override func prefersStatusBarHidden() -> Bool {    return true  }

but it doesn't work. the 3rd controller doesn't have the status bar as I am expecting. the 1st controller have the status bar of the same color of my nav bar but the 2nd controller doesn't get the nav bar color ( probably cause its not a nav controller, but just a navBar )

so how can I set the bar to have the color I want without getting it from the NavBarController? and how can I set the items in the status bar ( the icons... ) to have white color instead of black? ( the navbar text are white )

Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165
Marco
  • 81
  • 4
  • when i wanted to change the status bar i put in the appDelegate's applicationDidFinishLaunchingWithOptions [self.window setBackgroundColor: [UIColor whiteColor]]; – LanternMike Oct 31 '14 at 05:13

2 Answers2

0

If you want to change the color of the content in the status bar (without using the UIViewController/UINavigation Controller automatic stuff) (so your 2 view controller) you can use the setStatusBarStyle(_ statusBarStyle: UIStatusBarStyle, animated animated: Bool) on UIApplication. So place the following in viewWillAppear (or wherever it makes sense/works best) in your 2 view controller:

UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightConte​nt, animated: false)

Docs: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/#//apple_ref/occ/instm/UIApplication/setStatusBarStyle:animated:

0
setStatusBarStyle

Is now deprecated in iOS 9 and the current way of changing status bar style is:

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

Changing .Default to .LightContent for light

RJH
  • 358
  • 3
  • 12