Setting custom UINavigationBar images for left and right buttons
button, cocoa-touch, image, ios, uinavigationbar
Solution
This is pretty simple stuff, just alloc/initWithImage a couple of bar button items, then apply them.
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"myImage"] style:UIBarButtonItemStyleBordered target:self action:@selector(someMethod)];
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"myImage"] style:UIBarButtonItemStyleBordered target:self action:@selector(someMethod)];
[[self navigationItem] setLeftBarButtonItem:leftItem];
[[self navigationItem] setRightBarButtonItem:rightItem];
This of course assumes that you are actually using a navigation controller. If you just have a navigation bar that you dragged and dropped in interface builder, then you need to make an IBOutlet for the navbar, link it up and then use something like this:
UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:@"Title"];
[item setRightBarButtonItem:rightItem];
[myNavBar pushNavigationItem:item animated:NO];
You may need to add a flexible space in between.
Problem
This is what I have on my storyboard: And I wanna change both buttons images. I have a 13x46 image but I'm having problems using it as the button's images. I've searched around for some code but I wasn't very successful with them. Any ideas?