-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?

Steven
  • 762
  • 1
  • 10
  • 27
  • 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
  • 958
  • 1
  • 12
  • 37
  • Bu it won't call the preferredStatusBarStyle. – Steven May 14 '21 at 16:02
  • `preferredStatusBarStyle` is called by UIKit. – Morniak May 14 '21 at 16:07
  • I tried before writing the question, it doesnt work. – Steven May 14 '21 at 16:10
  • Did you set the `UIViewControllerBasedStatusBarAppearance` value in your .plist ? Did you call the `setNeedsStatusBarAppearanceUpdate` method in the `viewDidLoad` as suggested in the linked question ? – Morniak May 14 '21 at 16:21
  • View controller-based status bar appearance = NO, and called setNeedsStatusBarAppearanceUpdate() and it didn't work. – Steven May 14 '21 at 16:28
  • `UIViewControllerBasedStatusBarAppearance` should be set to YES if you are overriding it in your viewController. – Morniak May 14 '21 at 16:32
-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
  • 762
  • 1
  • 10
  • 27