Starting from iOS7 the status bar style can be modified in two different ways or, to say it better, with the following scopes:
- per-Controller, meaning that each controller will be able to have a different status bar style.
- per-Application, meaning that we will set a single style/color set that will be propagated in each controller of the Application.
Per-Controller
This is the default scope for iOS7+, meaning that the framework expects that we'll do our modifications inside each controller code file. In order to obtain such a result we need to add the following piece of code in the viewDidLoad method of our controller.m file:
1 |
[self setNeedsStatusBarAppearanceUpdate]; |
Then we just need to implement the preferredStatusBarStyle method, returning the status bar style we want to use for this view controller: for example, if we have a dark background we would definitely like to set up a light content like this:
1 2 3 |
- (UIStatusBarStyle) preferredStatusBarStyle { return UIStatusBarStyleLightContent; } |
If we have to deal with a light background we could better use the default style, which features a dark content:
1 2 3 |
- (UIStatusBarStyle) preferredStatusBarStyle { return UIStatusBarStyleDefault; } |
And so on.
Per-Application
If we want to have a single status bar style/color for any of our controllers, the first thing we have to do is to change the default settings. In order to do this we have to add a specific key to the Application's Custom Target Properties. These can be accessed by manually editing the info.plist file in the /Supporting Files/ folder or, using the GUI, by selecting the main application Target and then navigating through the Info tab:
Here's the key/value we need to add:
1 |
View controller-based status bar appearance : NO |
We can check the results of our changes by looking at the XCode user interface:
Once we did that we just have to add the following piece of code to the didFinishLaunchingWithOptions method inside the AppDelegate.m application file:
1 |
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; |
If you want to go further in styling your Status Bar we highly suggest to:
- read the official documentation page, which is full of hints and useful examples.
- check out this question in StackOverflow.
Happy reading and happy coding!