-3

preferredStatusBarStyle .lightContent doesn't work with Navigation Controller. I have tried this method below

override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent }

This is my first time to face this kind of issue. This code works in my Previous apps.

I even change this in my target:
I even change this in my target

Cœur
  • 37,241
  • 25
  • 195
  • 267
Swift
  • 37
  • 1
  • 9
  • Possible duplicate of [Preferred status bar style of view controller is ignored when in navigation controller](https://stackoverflow.com/questions/41026514/preferred-status-bar-style-of-view-controller-is-ignored-when-in-navigation-cont) – Robin Daugherty Oct 15 '18 at 05:59

2 Answers2

2

I think you forget to change statusbar style in info.plist

Change in info.plist the row View controller-based status bar appearance and set it to YES

and in Your ViewController:

 override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent } 

No other code is required

Jaydeep Vyas
  • 4,411
  • 1
  • 18
  • 44
-1

Make sure that in your Info.plist file you have View controller-based status bar appearance set to NO. It would also be helpful to check that you don't programatically set the status bar to a different color in a view controller by accident. If you're using the above function, do you call self.setNeedsStatusBarAppearanceUpdate? But you shouldn't need to write any code at all if you set Light as the value in your project settings and NO in your plist file.

Another option that has worked for me in the past is in your AppDelegate file, in the didFinishLaunchingWithOptions function do this:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    UIApplication.shared.statusBarStyle = .lightContent

    return true
}
ch1maera
  • 1,369
  • 5
  • 20
  • 42
  • i have set it to no , seconde I don't want to set it in app delegate if I do that the entire app will be what inside app delegate – Swift Feb 06 '18 at 05:24
  • The entire app will not be inside of app delegate – putting the code in app delegate merely makes the code applicable to every file and object in your app. – ch1maera Feb 06 '18 at 05:48
  • it's work but with this code every viewController will be set to light content – Swift Feb 06 '18 at 05:54
  • Do you only want specific view controllers to have a light status bar or all of them? If you want specific view controllers, you'll need to set the value in the plist to yes, include the specific code, and then call `setNeedsStatusBarAppearanceUpdate` in the `viewDidLoad` method of each view controller you want to have a light status bar. – ch1maera Feb 06 '18 at 06:13
  • i had do what you just said nothing work, it's maybe an Xcode issue I will delete my app and rebuild it thanks for your time – Swift Feb 06 '18 at 06:24
  • 1
    the problem was i had a navigation controller try those methods on navigationController and see your self if it's will work or not – Swift Feb 06 '18 at 06:48