UIColor Issues in Navigation Bar Settings? Xcode 12.1

HI All,

I saw a topic on this previously, but it was related to Xcode 11 (late 2019). I am getting really frustrated with trying to set custom navigation bar colors for different view controllers.

The code is working only with the system default colors (below) :

//    override func viewWillAppear( animated: Bool) {

//        super.viewWillAppear(true)

//        self.navigationController?.navigationBar.barTintColor = UIColor.system*"color"*


When I try creating a custom UI Color, my navigation bar just defaults to white. Nothing is changing this. I have tried every variation of the code below including UIColor.init as well as placing in viewDidApppear. Absolutely nothing is working and I'm starting to think it is an Xcode problem. Unless there is something I am missing?


//    override func viewWillAppear(
animated: Bool) {

//        super.viewWillAppear(true)

//        self.navigationController?.navigationBar.barTintColor = UIColor(red: 250, green: 190, blue: 110, alpha: 1)

//    }

Anyone else having similar problems?

Hi 🤙🏻
You miss the /255

should be like this:
Code Block
UIColor(red: 250/255, green: 190/255, blue: 110/255, alpha: 1)


also try to set the color when you push the view

Code Block
let view = PasajerosPaso2View()
        view.backgroundColor = UIColor.lightGray
        navigationController.navigationBar.backgroundColor =  UIColor(red: 250/255, green: 190/255, blue: 110/255, alpha: 1)
        let vc = factory.makePasajerosPaso2VC(view, coordinator: self)
        navigationController.pushViewController(vc, animated: false)

Setting navigationBar.backgroundColor in each viewController in the navigation stack will do it
Code Block
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.navigationController?.navigationBar.backgroundColor = UIColor(red: 1.0, green: 0.1, blue: 0.1, alpha: 1.0)
}

That changes the color of the navigation controller; so you may need to reset in each VC of the stack.
UIColor Issues in Navigation Bar Settings? Xcode 12.1
 
 
Q