Swift iOS8 StatusBar

Status Bar Style in iOS8

Status Bar Style in iOS8

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 :)

comments powered by Disqus