Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation bar button item image color is different when design through xib of xcode5

I am creating navigation bar button using xib but when i going to set image to bar button then image colour is different as original image.

Here is my orignal image.

Here is my orignal image

And after adding that image on navigation bar button item than it look like this

Aafter adding that image on navigation bar

like image 501
Bug Avatar asked Jan 21 '14 07:01

Bug


1 Answers

First, I agree with @Desdenova's comment.
The two images do not look the same, one has hard right angle edges for each line, and the other rounded.
Make sure you are using the correct image file.
If this is the case, awesome, problem solved without deviating from your xib implementation. If not, just do it programmatically (as per @shankars code).
But another thing to note, I've run into problems setting custom image files to buttons, where the image gets tweaked... make sure to use UIImageRenderingModeAlwaysOriginal when setting the image to the button:

Objective-C:

[button setImage:[[UIImage imageNamed:@"imageName.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal]; 

Swift:

someBarButtonItem.image = UIImage(named: "yourPictureName")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal) 

Swift 3:

someBarButtonItem.image = UIImage(named:"myImage")?.withRenderingMode(.alwaysOriginal) 
like image 112
Daniel McCarthy Avatar answered Oct 02 '22 14:10

Daniel McCarthy