0

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?

Steven
  • 497
  • 8
  • 21
  • Does this answer your question? [How to change Status Bar text color in iOS](https://stackoverflow.com/questions/17678881/how-to-change-status-bar-text-color-in-ios) – Morniak May 14 '21 at 15:34
  • Also, check your syntax, you might have a missing '}' – Morniak May 14 '21 at 15:37
  • Thank you but the links didn't answer my question. and I checked the syntax, it is not missing – Steven May 14 '21 at 15:48

2 Answers2

-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()
    }
}
Morniak
  • 855
  • 1
  • 12
  • 31
-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

Steven
  • 497
  • 8
  • 21