1

I have a UINavigationBar with a blue tint set by its appearance:

[UINavigationBar appearance].tintColor = [UIColor blueColor];

During the navigation I have one UIBarButtonItem, connected to an outlet, that I want red! So naively, as I wished to keep all the other buttons of my bar blue, I tried that in the viewWillAppear: callback:

self.myOughtToBeRedButton.tintColor = [UIColor redColor];

And guess what? It's still blue!!!

If someone has an idea... I need to tun it on both iOS 7 & iOS 8.

Thanks in advance.

Zaphod
  • 6,758
  • 3
  • 40
  • 60

2 Answers2

0

You can do this by setting the UIBarButtonItem's title text attributes in viewDidLoad:

actionButtonItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.redColor()], forState: .Normal)

That single button will be red, and remaining items will use the navigation bar's tintColor. No custom button necessary.

BrentM
  • 249
  • 1
  • 4
  • Thanks for your answer, but that only changes the text color. I need the tint to be changed, for instance when the button displays a glyph. – Zaphod Aug 17 '15 at 13:27
0

If you want to keep the original UIBarButton's image. Change the type o render at Images.xcassets. Like this:

Allan Scofield
  • 1,884
  • 18
  • 14