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?
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:
Here's lootsch's (excellent) answer converted to Swift 3 / Swift 4:
barButton.image = UIImage(named: "imageName")?.withRenderingMode(.alwaysOriginal)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With