3
votes

I want to set black color(bar tint color) of status bar and white tint color when navigation bar is hidden.

And I want it for specific views. I have tried this:

override func viewDidLoad() 
{
    super.viewDidLoad()

    self.navigationController?.setNavigationBarHidden(true, animated: true)

    self.navigationController?.navigationBar.barStyle = UIBarStyle.Black

    self.navigationController?.navigationBar.barTintColor = UIColor.blackColor()

    self.navigationController?.navigationBar.tintColor = UIColor.whiteColor()

}

I also tried this thing: I set the value to NO in P-list for View controller-based status bar appearance.

2

2 Answers

2
votes

If you are trying to change the status bar color, you can use

UIApplication.sharedApplication().statusBarStyle = .LightContent

Keep in mind you cannot set the status bar color to anything other than LightContent and the default (black). You can however set the status bar to light and throw an element behind it with a different color.

If you want a true way to override the color to make it black (default) or light, you can also try

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
}

In the view controllers you want to override. If you need a different background color, throw a UILabel behind it with a color and specify light content or default as the color.

1
votes

Just write these two lines in viewdidload

self.navigationController?.setNavigationBarHidden(true, animated: true)
setNeedsStatusBarAppearanceUpdate()

and paste this function anywhere in that ViewController class

override var preferredStatusBarStyle: UIStatusBarStyle {
   return .lightContent
}