Skip to content

Changing the Status Bar Color for specific ViewControllers using Swift in iOS8

After reading all the suggestions, and trying out a few things, I could get this to work for specific viewcontrollers using the following steps :

First Step:

Open your info.plist and insert a new key named “View controller-based status bar appearance” toNO

Second Step (Just an explanation, no need to implement this):

Normally we put the following code in the application(_:didFinishLaunchingWithOptions:) method of the AppDelegate,

UIApplication.sharedApplication().statusBarStyle = .LightContent

but that affects the StatusBarStyle of all the ViewControllers.

So, how to get this working for specific ViewControllers – Final Step:

Open the viewcontroller file where you want to change the StatusBarStyle and put the following code in viewDidLoad(),

UIApplication.sharedApplication().statusBarStyle = .LightContent

Also, implement the viewWillDisappear() method for that specific viewController and put the following lines of code,

override func viewWillDisappear(animated: Bool) {super.viewWillDisappear(animated)UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.Default }

This step will first change the statusBarStyle for the specific viewcontroller and then change it back to default when the specific viewcontroller disappears. Not implementing the viewWillDisappear() will change the StatusBarStyle permanently to the new defined value of UIStatusBarStyle.LightContent

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: