Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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

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

To keep the original colours of the image, you would have to assign the image to the button from code rather than from your storyboard.

  1. Reference your Button Outlet in your class file (usually a ViewController)
  2. Assign the image to the button from code:

    [self.bbiHome setImage:[[UIImage imageNamed:@"icon.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

You can set the tint color by default.

sample image

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top