2

I'm trying to set a navigation bar item through storyboard with custom image and it does not work.

This is the result:

enter image description here

The image I'm using is not a blue circle, here is the settings and object structure:

enter image description here

enter image description here

The image has the appropriate size and I have tried with multiple images all with the same result.

rhedin
  • 71
  • 1
  • 3
  • 20
  • Does your png file have an alpha channel? Sometimes the icon just gets colored in if not. – Douglas Feb 06 '16 at 16:47
  • For educational purposes, how do you know that? – rhedin Feb 06 '16 at 17:31
  • 1
    I used a png without alpha once on a tab bar item and all that appeared was a colored icon just like yours. Changed the alpha and it worked. The tint color sort of took over. – Douglas Feb 06 '16 at 19:47

1 Answers1

3

This is because navigation bar treats it's images as templates and will display them by applying standard Tint Color.

To display an image in it's original form you need to use UIImageRenderingModeAlwaysOriginal as rendering mode of the image.

You can set this in viewDidLoad method of your UIViewController

- (void)viewDidLoad {

    UIBarButtonItem* rightButton = self.navigationItem.rightBarButtonItem;
    [rightButton setImage:[[UIImage imageNamed:@"imageName"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
}
UditS
  • 1,936
  • 17
  • 37