Search code examples
iosswiftuinavigationcontrollerpushviewcontroller

PushViewController & set navigation bar color and title


I made a push function in a button:

@IBAction func prodButton(sender: AnyObject) {

    let storyboard = UIStoryboard(name: "Main", bundle: nil)

    var secondViewController = CollectionViewController()

    secondViewController = storyboard.instantiateViewControllerWithIdentifier("CollectionViewController") as! CollectionViewController

    self.navigationController?.pushViewController(secondViewController, animated: true)
}

This button pushes to the secondViewController but when I looked at the navigation bar of the second view controller I noticed that it has set up a back button automatically. The problem is that this back button's color is light blue and it doesn't fit with my design. I tried to change it like that in viewDidAppear

self.navigationItem.leftBarButtonItem?.tintColor = UIColor.redColor()

and also the bar color:

self.navigationController?.navigationBar.barTintColor = UIColor(red: 65, green: 61, blue: 116, alpha: 1.0)

but there wasn't any change.

I'd be really thankful if somebody help me with that.

Thanks in advance.


Solution

  • Try to set your color one time, it will be the same color for everywhere after:

    let navBar = UINavigationBar.appearance()
    navBar.tintColor = UIColor.redColor()
    

    You should put this code in AppDelegate. You could also set the barTint in Storyboard if you use it.