Yalantis/ColorMatchTabs

Cannot change navigationBar background Color

imenacmc opened this issue · 2 comments

I'm trying to change the navigationBar backgroundColor but always let white.

This is my code

    self.navigationController?.navigationBar.backgroundColor = UIColor.blue
    self.navigationController?.navigationBar.barTintColor = UIColor.blue
    self.navigationController?.navigationBar.tintColor = UIColor.purple
    self.navigationController?.navigationBar.isTranslucent = false

tintColor works but backgroundColor and barTintColor don't.

¿Any suggestion?

rnkyr commented

Hey, @imenacmc!
Since your question is not related to ColorMatchTabs I'm about to close it.
But fast googling points me to that solution which seems to be working.

Hey, @imenacmc!
In ColorMatchTabsViewController.swift's file you have to comment three rows as follows if you want change navigation bar color:

 func setupNavigationBar() {
        //navigationController?.navigationBar.shadowImage = UIImage(namedInCurrentBundle: "transparent_pixel")
        //let pixelImage = UIImage(namedInCurrentBundle: "pixel")
        //navigationController?.navigationBar.setBackgroundImage(pixelImage, for: .default)
        
        titleLabel.frame = CGRect(x: 0, y: 0, width: 120, height: 40)
        titleLabel.text = title
        titleLabel.textAlignment = .center
        navigationItem.titleView = titleLabel
    }

Then in your ViewWillAppear in your ViewController you can use:
self.navigationController?.navigationBar.backgroundColor = UIColor.blue self.navigationController?.navigationBar.barTintColor = UIColor.blue self.navigationController?.navigationBar.tintColor = UIColor.purple self.navigationController?.navigationBar.isTranslucent = false

Bye