Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Navigation Item

How can I change the color of the Navigation Item using swift? Stone Preston Stephen Whitfield

Navigation Item?

the back button

4 Answers

I actually misled you a bit. The bar buttons added in Storyboard are custom buttons and you wouldn't get the back bar button that you get for free from creating a navigation stack. You'd have to create your own back bar button indicator image and explicitly define a method that pops the current view off the nav stack and assign it to this custom button, but lets not do all of that. Just stick with the code I gave you earlier and put it in your "viewWillAppear" method.

Thank you so much, it worked perfectly! Happy holidays.

  1. Set the tintColor of the nav bar to the color you want to use for the back bar button, then set the back bar button.
self.navigationController?.navigationBar.tintColor = UIColor.redColor()
        self.navigationItem.backBarButtonItem?.tintColor = UIColor.redColor()

If you are adding bar buttons in Storyboard, you have the luxury of setting the bar buttons each to whichever color you choose in the attributes inspector. Are you Storyboarding or building this app programmatically?

I am storyboarding, but the back button only shows in the simulator, and I am unsure of how to select it in the storyboard. Could you tell me how? Stephen Whitfield

Stone Preston
Stone Preston
42,016 Points

What do you mean by navigation item exactly? The whole navigation bar text? the back button only?

if you want the color to be application wide you should put it in the app delegate under did finish launching with options using the UIAppearance proxy

UINavigationBar.appearance().tintColor = SomeColorHere
        UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: SomeColorHere]

Sorry, I meant the back button. Stone Preston