Nick Kohrn
Nick Kohrn

Reputation: 6049

Why Is My Status Bar Not Changing Preferred Style?

I have View controller-based status bar appearance set to YES in my Info.plist file.

The view controller, not in a navigation stack, is presented via a modal segue. In it, I have the following property override for Swift 3/iOS 10:

override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent }

Still, the status bar retains its default (dark) styling. However, when I print preferredStatusBarStyle in viewDidLoad, I get a rawValue of 1. Checking out the documentation, 1 refers to .lightContent.

I am trying to change the status bar's style to .lightContent because the view contains a UIVisualEffectView with a UIBlurEffectStyle value of dark.

Am I doing something incorrectly?

Upvotes: 2

Views: 4209

Answers (3)

Sour LeangChhean
Sour LeangChhean

Reputation: 7419

  1. Go to info.plist and set UIViewControllerBasedStatusBarAppearance to false
  2. Go to AppDelegate.swift then go to function didFinishLaunchingWithOptions, set the color you want as below:

    UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent

Please let me know if it can help you. Thanks.

Upvotes: -2

Nick Kohrn
Nick Kohrn

Reputation: 6049

With help from matt's answer, I was able to resolve my issue. I had to use the following in viewDidLoad:

modalPresentationCapturesStatusBarAppearance = true

When I tried matt's solution, I received two compilation errors: Cannot override mutable property with read-only property 'modalPresentationCapturesStatusBarAppearance' and Getter for 'modalPresentationCapturesStatusBarAppearance' with Objective-C selector 'modalPresentationCapturesStatusBarAppearance' conflicts with getter for 'modalPresentationCapturesStatusBarAppearance' from superclass 'UIViewController' with the same Objective-C selector

Upvotes: 7

matt
matt

Reputation: 535989

Add this to the modally presented view controller:

override var modalPresentationCapturesStatusBarAppearance: Bool { 
    return true
}

Upvotes: 5

Related Questions