Site icon Ryadel

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:

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:

If we have to deal with a light background we could better use the default style, which features a dark content:

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:

app-info.plist
Two different ways to achieve our goal: reach the Custom Target Properties.

 

Here's the key/value we need to add:

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:

If you want to go further in styling your Status Bar we highly suggest to:

Happy reading and happy coding!

 

 

Exit mobile version