简体   繁体   中英

Changing Color of Navigation Bar Independently

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;

多个导航控制器

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM