Can not override the preferredStatusBarStyle

125 Views Asked by At

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?

2

There are 2 best solutions below

0
Steven On BEST ANSWER

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

6
Morniak On

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()
    }
}