BilalReffas
BilalReffas

Reputation: 8328

Issue with UIBarButtonItem

I have a problem with my UIBarButton the button have a different color than my original image.

  self.navigationItem.rightBarButtonItem =  UIBarButtonItem(image: UIImage(named: "settings.png"), style: .Plain, target: self, action: "didTapSettingButton")

The color of the button is blue but my image is something like yellow !

Like this : enter image description here

It would be awesome if you can help me :)

Upvotes: 0

Views: 122

Answers (3)

Dharmesh Dhorajiya
Dharmesh Dhorajiya

Reputation: 3984

set image UIImageRenderingMode property:

 self.navigationItem.rightBarButtonItem =  UIBarButtonItem(image: UIImage(named: "settings.png").imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), style: .Plain, target: self, action: "didTapSettingButton")

Upvotes: 2

Amit89
Amit89

Reputation: 3000

Try like this.

Create a bar button property in your class var settingRightBarButton : UIBarButtonItem?

then

let shareBarButtonImage = UIImage(named: "settings")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
self.settingRightBarButton = UIBarButtonItem(image: shareBarButtonImage, style: UIBarButtonItemStyle.Plain, target: self, action: Selector("didTapSettingButton"))
self.navigationItem.rightBarButtonItem = self.settingRightBarButton

Add your images in Images.xcassets

Upvotes: 0

Jay Bhalani
Jay Bhalani

Reputation: 4171

Try This code :

var image : UIImage? = UIImage(named:"settings.png").imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)

Upvotes: 2

Related Questions