Ben Dodson

Freelance iOS, Apple Watch, and Apple TV Developer

Forcing UIStatusBarStyle for UIImagePickerController

I stumbled upon an interesting problem today which I’ve experienced a couple of times before; if you are using white text for the status bar in your application (UIStatusBarStyle.LightContent) then it will be turned black once you present a UIImagePickerController. This can not only look ugly but will remain when you dismiss the controller. Usually I just change the appearance of the navigation bar within the picker to get around this (and set it back to the correct colour upon dismissing the controller) but on this particular app I wanted to force the UIImagePickerController to use the light style status bar. Fortunately it is quite easy.

When you use the UIImagePickerControllerDelegate, you are also required to adopt the UINavigationControllerDelegate. This has a method named navigationController:willShowViewController:animated: which will be called both when you present the controller and when you navigate between albums. Using this, it is trivial to force the status bar to remain the same1:

func navigationController(navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool) {
	UIApplication.sharedApplication().statusBarStyle = .LightContent
}
  1. This is of course assuming you have View controller-based status bar appearance set to NO in your Info.plist file so that you can use UIApplication to change the status bar. ↩︎

UK Apple Pay » « Optical media and the pain of Remote Disc