Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIBarButtonItem is blue instead of image

Here is what I have in my viewDidLoad method:

self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "back")
self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "back")
self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: UIBarButtonItemStyle.Plain, target: nil, action: nil)

I am trying to have a custom icon image for my back button in my navigation controller. Instead of the image showing in it's original format, I am seeing the image in blue. How do I get the image to show properly?

like image 501
Katie H Avatar asked Jan 26 '26 10:01

Katie H


2 Answers

You can use renderingMode for your custom image with AlwaysOriginal mode. See below code for solved it.

self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "back")?.imageWithRenderingMode(.AlwaysOriginal)
self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "back")?.imageWithRenderingMode(.AlwaysOriginal)

Hope that helps!

like image 122
Long Pham Avatar answered Jan 28 '26 00:01

Long Pham


Quickest solution

.navigationController?.navigationBar.tintColor = UIColor.redColor()

Or you can create custom barButton item, with custom view

like image 36
Andrius Steponavičius Avatar answered Jan 28 '26 01:01

Andrius Steponavičius



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!