I'm using Xcode 8.0 beta 4.
In previous version, UIViewController have method to set the status bar style
public func preferredStatusBarStyle() -> UIStatusBarStyle
However, I found it changed to a "Get ONLY varaiable" in Swift 3.
public var preferredStatusBarStyle: UIStatusBarStyle { get }
How can provide the style to use in my UIViewController?
Latest Update (Xcode 10+ / Swift 4.2+)
This article is left intact for anyone willing to understand the logic behind different approaches that were present for the past several years. Meanwhile, as of Xcode 10, Swift 4.2 first approach is deprecated and is no longer supported (i.e. will not take effect if you try to employ it). It's still referred for your information to better understand the reasoning behind
Plist.info
flag and customizing practice.Important clarification
It is very important to understand two approaches to customizing the status bar appearance. They are different and should not be mixed.
First approach – one color for whole app (DEPRECATED since iOS7)
In info.plist you find or create a key called
View controller-based status bar appearance
and set it to NO.
What it does? It essentially establishes a setting that says that in your application, status bar appearance is not defined individually by each view controller. This is super important to understand. This means that you have uniform setting for entire app, for all screens. There are two settings:
default
, which is black text on white background, orlightContent
, which is white text on black background.To set one of these up (one setting for all screens):
This way you won't need to reestablish this setting on each view controller. However, you can always resort to this method to voluntarily change appearance.
Second approach – individual color for each view controller
This is the opposite. To make it work, go ahead to info.plist and set
View controller-based status bar appearance
to YES
This way, whenever a new view controller is open, status bar style is set individually if you insert this implementation in each
UIViewController
instance you need:You have the same as in first, set either dark or light style for statusbar, individual to each view controller.
Third approach – Hack!
There's a hack which allows to access statusbar directly:
Why hack? If you need status bar color other than black or white, you use undocumented API. You get
statusBar
object using KVC and set its background color. Object you get this way isUIStatusBar
, which is derived fromUIView
and thus naturally supportsbackgroundColor
property. This is dirty, not legal way, but so far it's the only way to set up custom color for statusbar (not taking into accountUINavigationBar
approach, which allows to customize navbar+statusbar appearance altogether). It may well lead your app to being rejected. But maybe you're lucky. And if you are, in certain complex circumstances (like hierarchy of nested, child navigation and view controllers) this may be pretty much the only, or at least the less troublesome way to customize statusbar appearance (for example, to make it transparent)Xcode 10+, Swift 4.2
There are no alternatives any more: developer should let each view controller define statusbar appearance, by setting the flag to YES (or omitting this action, because it's YES by default) and following above instructions.
Bonus
Hack-based solution you might (although not encouraged to) use in complex circumstances in order to voluntarily change statusbar appearance at any stage. Color-wise, the following extension method does exactly what you could have done with regular approach. You can adjust it to your needs.
Swift 3
To set the same appearance of navigation Bar across your app, you can do this in AppDelegate.swift:
Swift 3
In Info.plist add a row called "View controller-based status bar appearance" and set its value to
No
.Most of these answers are the same thing re-hashed, but none of them actually address the launch screen for me when using a dark background.
I got around this with the following in my
info.plist
which produced a light styled status bar.