Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIBarButtonItem image stays blue and not the original color of the image?

How come the icon info.png stays blue and don't comes with the original color of that image? I am using the following code below:

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"info.png"]
                                                                             style:UIBarButtonItemStylePlain
                                                                            target:self
                                                                            action:@selector(info:)];
like image 467
Jan Avatar asked Nov 10 '14 23:11

Jan


3 Answers

By default, image in UINavigationBar's bar button items is rendered using template mode. You can set it to original.

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"info.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
                                                                         style:UIBarButtonItemStylePlain
                                                                        target:self
                                                                        action:@selector(info:)];
like image 199
Peter Avatar answered Oct 18 '22 00:10

Peter


Swift 3:

let image : UIImage? = UIImage.init(named: "heart.png")!.withRenderingMode(.alwaysOriginal)
like image 26
selma.suvalija Avatar answered Oct 18 '22 01:10

selma.suvalija


I know this is too late to answer this question but I see there is a very simple way to solve this issue instead of doing some changes in the code

using Xcode Go to the Assets --Select Image --- check Render as and select Original image instead of default property .

enter image description here

like image 17
nivritgupta Avatar answered Oct 18 '22 00:10

nivritgupta