XCode: set Status Bar style and color in Objective-C

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

[selfsetNeedsStatusBarAppearanceUpdate];

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{

returnUIStatusBarStyleLightContent;

}

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{

returnUIStatusBarStyleDefault;

}

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:

Two different ways to achieve our goal: reach the Custom Target Properties.

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:

About Ryan

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites & services hosted in Italy and Europe. Since 2010 it's also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies.

This site uses cookies to improve user experience, personalize content & ads, provide social media features and analyze our traffic: some of these info are shared with our social media, advertising and analytics partners. We assume you're okay with this, but you can opt-out if you wish. Read the Privacy Policy for further info.