Reputation: 8328
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 :
It would be awesome if you can help me :)
Upvotes: 0
Views: 122
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
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
Reputation: 4171
Try This code :
var image : UIImage? = UIImage(named:"settings.png").imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
Upvotes: 2