← All notes

Log 06 · From the 2015 archive

Setting StatusBar Font Color in iOS8

Filed
Reading
1 min
Tags
  • Swift
  • iOS8
  • StatusBar
Flat illustration of a paper phone with a dark status bar and white icons above a teal screen on a dark brown wall.
Two iOS 8 simulator status bars: dark text on white, then white text on an orange background.

This one is a quick thing that I keep forgetting how to do. While developing iOS apps, sometimes we need to change the color of the font in the status bar (which is dark by default). We have the option to change the status bar to a white color (or “light” style).

First we need to define the following to the app’s info.plist: View controller-based status bar appearance. It takes a BOOL (YES or NO). Let’s look at what each means:

  • YES: This will allow us to to set the preferredStatusBarStyle in our view controllers, like so:
override func preferredStatusBarStyle() -> UIStatusBarStyle {
    return UIStatusBarStyle.LightContent
}
  • No: We can still set it with the following (it has worked for me either in the appDelegate and/or inside each ViewController:
UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: true)

Hope this helps someone :)

← All notes