1

I am trying to add some buttons to my UINavigationBar. It seems I can't just drag and drop an item into the bar, is this correct? So I a using this code below but for some reason the cog icon I am using is appearing as blue but it's actually a gray colour. How can I use the original image colour? Any help would be appreciated!

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"cog"] style:UIBarButtonItemStylePlain target:nil action:nil];
Kex
  • 8,023
  • 9
  • 56
  • 129

2 Answers2

4

You need to explicitly specify rendering mode when creating image, as suggested in this answer:

UIImage *image = [[UIImage imageNamed:@"cog"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:nil action:nil];
Community
  • 1
  • 1
Maxim Pavlov
  • 2,962
  • 1
  • 23
  • 33
0

Change the tint color of your navigation bar or the UIBarButtonItem to achieve the desired result.

If you need to change the tint color in the whole app, update the [UINavigationBar appearance] in your AppDelegate.m

Vlad Fedoseev
  • 152
  • 1
  • 11