jamesMcKey
jamesMcKey

Reputation: 491

How to change the background color of navigationBar

I am trying to change the background color of the navigation bar to black but without success. I have checked the answer to this related question but none of the solutions have worked. This is what I have tried:

navigationController?.navigationBar.backgroundColor = UIColor.black
UINavigationBar.appearance().backgroundColor = UIColor.black

Upvotes: 1

Views: 55

Answers (2)

Frankenstein
Frankenstein

Reputation: 16341

Try this:

UINavigationBar.appearance().barTintColor = .black
UINavigationBar.appearance().isTranslucent = false

Note: This changes the bar colour for the entire app.

Upvotes: 0

Asif Newaz
Asif Newaz

Reputation: 587

You can also change the navigation bar color for a specific view controller, this way:

extension UIViewController {
    func setCustomNavigationColor(color: UIColor = .black, isTranslucent: Bool = false ){
        self.navigationController?.navigationBar.barTintColor = color
        self.navigationController?.navigationBar.isTranslucent = isTranslucent
    }
}

call this from viewDidLoad()

setCustomNavigationColor()

Upvotes: 1

Related Questions