-1

In dark mode style, the status bar disappear cause of dark color.

I added the:

 override var preferredStatusBarStyle: UIStatusBarStyle {
            return .lightContent
        }

but the problem is, when I add the method in "viewDidLoad" I get the error:

override can only be specified in class member

any idea how to resolve this?

3
  • Does this answer your question? How to change Status Bar text color in iOS Commented May 14, 2021 at 15:34
  • Also, check your syntax, you might have a missing '}' Commented May 14, 2021 at 15:37
  • Thank you but the links didn't answer my question. and I checked the syntax, it is not missing Commented May 14, 2021 at 15:48

2 Answers 2

-1

preferredStatusBarStyle is a member of the UIViewController class. What you want to do here is to override this class member. The snippet in your question have nothing to do in the viewDidLoad method and should be placed in your subclass body like this :

class YourViewController: UIViewController {
    override var preferredStatusBarStyle: UIStatusBarStyle {
        return .lightContent
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
}
Sign up to request clarification or add additional context in comments.

6 Comments

Bu it won't call the preferredStatusBarStyle.
preferredStatusBarStyle is called by UIKit.
I tried before writing the question, it doesnt work.
Did you set the UIViewControllerBasedStatusBarAppearance value in your .plist ? Did you call the setNeedsStatusBarAppearanceUpdate method in the viewDidLoad as suggested in the linked question ?
View controller-based status bar appearance = NO, and called setNeedsStatusBarAppearanceUpdate() and it didn't work.
|
-1

I am going to answer the question here, maybe it can help someone else:

After hours checking my codes, I found out that I have rootViewController which I used as a authentication then after the authentication user pass to TabbarViewController... which is not rootViewController, I added the:

preferredStatusBarStyle

To my rootViewController and it works.

View controller-based status bar appearance should be YES

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.