set custom color of status bar in swift?

Viewed 2779

On a view controller, i want to set the color of status bar black but I am not able to change it. I am using below code for this purpose.

 func setUpUI() {
        self.navigationController?.setNavigationBarHidden(true, animated: false)
        UIApplication.shared.statusBarStyle = UIStatusBarStyle.default
    }

I have also added the value in info.plist

enter image description here

2 Answers

You just override the return value of the status bar, like this:

override var preferredStatusBarStyle: UIStatusBarStyle {
   return .lightContent
}
Related