首页 > 解决方案 > Bar button item image (UIImage) color changes with tint color?

问题描述

I am trying to set an image for bar button item based on a condition. I need to show 2 different images. The tint color property is affecting the color of my image itself. How to change this? When i give “clear color” as tint color the image is not getting displayed at all.

标签: iosswiftxamarin.iosuibarbuttonitemrightbarbuttonitem

解决方案


用这个

斯威夫特 2.x

var image = UIImage(named:"myImage").imageWithRenderingMode(.AlwaysOriginal)

斯威夫特 3.x 或 4

var image = UIImage(named:"myImage")?.withRenderingMode(.alwaysOriginal)

并将其设置为您的 UIBarButtonItem


推荐阅读