Search code examples
iosswiftswift3statusbarviper-architecture

Enabling lightContent status bar style in a VIPER project


In previous versions of Swift, to change the status bar style I would use 'preferredStatusBarStyle' and return .lightContent.

This method is now unavailable, I have tried every solution on SO such as:

    self.navigationController?.navigationBar.barStyle = UIBarStyle.black
    self.navigationController?.isNavigationBarHidden = true

However, these techniques do not work. Can someone please shed some light on this. Currently in my plist, I have 'statusBarStyle' set to 'UIStatusBarStyleLightContent'.

You're welcome to download my project here: https://github.com/benskill/Flash-Flags


Solution

  • In iOS 10, preferredStatusBarStyle is a property, not a method. So instead of overriding it with a func declaration, you override the getter with a var declaration.

    override var preferredStatusBarStyle: UIStatusBarStyle {
       return .lightContent
    }