4

I'm updating an iOS app for iOS 12 and ran into this warning.

I'm changing the status bar in the AppDelegate.swift file for my app. This can be found in the didFinishLaunchingWithOptions function

UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent

I'm getting a warning that says this:

Setter for 'statusBarStyle' was deprecated in iOS 9.0: Use -[UIViewController preferredStatusBarStyle]

I thought this would be an easy update, but I haven't found an update that has worked for me.

I tried setting this on the main VC:

// set the status bar color
override var preferredStatusBarStyle : UIStatusBarStyle {
    return .lightContent
}

But it's not displaying in light mode.

When I try and type the override out myself, this is what I get for code hinting.

Rivera
  • 10,792
  • 3
  • 58
  • 102
icekomo
  • 9,328
  • 7
  • 31
  • 59
  • Show what you have tried so far. – rmaddy Sep 13 '18 at 02:16
  • @rmaddy, I posted my code as to what I have tried. This method seemed to work in Swift 3, but I'm not sure its working in Swift 4. I don't get code hinting when I try to type of the new override var. – icekomo Sep 13 '18 at 21:31

1 Answers1

3

Going through the UIApplication documentation, it seems that there is no alternative symbol there for setting the status bar style. Instead, I would do what the warning instructs: Use -[UIViewController preferredStatusBarStyle].

You could set the status bar background color, but that doesn't seem to be what you're looking for.

Given the limitations, it seems that Apple wants us to have view controllers set the status bar style. I'm not sure why this is better from a design perspective, but there doesn't seem to be much legal stuff we can do about it.

Daniel
  • 3,188
  • 14
  • 34