UIBarButtonItem is blue instead of image

谁说胖子不能爱 提交于 2019-12-01 07:12:06

问题


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?


回答1:


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!




回答2:


Quickest solution

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

Or you can create custom barButton item, with custom view




回答3:


Set the tintColor property of the barbuttonItem.

self.navigationItem.backBarButtonItem.tintColor = "any color"


来源:https://stackoverflow.com/questions/33760806/uibarbuttonitem-is-blue-instead-of-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!