Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation Bar Button Item Tint

Is it possible to drag a navigation bar button item to the navigation bar, use an image, and NOT have tint applied so that the original image appears as intended? Or is this only possible by adding nav bar button items via code?

Example: My dark background nav bar has white as the default tint, but I have an orange image icon I want to appear for one of the buttons. If I drag a bar button item & set the image, it appears white. Can I change (or remove) the tint for this one button? Or, do I need to forget the visual editor and create this button programmatically to control the tint?

like image 664
I'm Joe Too Avatar asked Apr 01 '14 15:04

I'm Joe Too


2 Answers

If you want to keep the original colors of the image, you have to do it in code:

[button setImage:[[UIImage imageNamed:@"imageName.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];

If you want to overwrite the tint color of your button (e.g.: orange only) you can achieve that inside your storyboard. Just set the tint color of your Bar Button Item inside Xcode's Attributes Inspector to the desired color:
Xcode Screenshot

like image 116
lootsch Avatar answered Oct 17 '22 01:10

lootsch


Here's lootsch's (excellent) answer converted to Swift 3 / Swift 4:

barButton.image = UIImage(named: "imageName")?.withRenderingMode(.alwaysOriginal)

like image 36
brookinc Avatar answered Oct 17 '22 03:10

brookinc