2
votes

Before I begin, please know that I have read through a number of StackOverflow posts on the topic, yet I've been unable to figure out how to apply many answers to my specific scenario.

In my Storyboard, I have a Table View with an embedded navigation controller, and a segue to another Table View with an embedded navigation controller. Based on the design of my app, I am seeking the navigation bar in the first table view to have a different background (tint) color than the navigation bar in my second table view. Here's my layout;

Multiple Navigation Controllers

Per the above, I set the color of my first Navigation Controller bar to be green, and my second Navigation Controller to be blue. However, when I build and run the app, the second Table View has a green navigation controller, whereas I've set it to blue in Interface Builder.

I've tried to use the following code in my SecondTableViewController.swift file;

navigationController.navigationBar.barTintColor = UIColor.blueColor() self.navigationBar.tintColor = UIColor.blueColor()

Is this possible? Or am I misunderstanding how the navigation controller works?

1
you also need to set the translucency... self.navigationController.navigationBar.translucent = falseWoodstock

1 Answers

2
votes

To set all UINavigationBar instances at once to the same color do this:

UINavigationBar.appearance().barTintColor = UIColor.greenColor()

To set per instance (as you need), try this:

self.navigationBar.tintColor = UIColor.blueColor()
self.navigationController.navigationBar.translucent = false