I'm having trouble applying a tint color the navigation item's back bar button item when I create the bar button item with -[UIBarButtonItem initWithImage:style:target:selector:].
Is using an image as a view controller back context no longer okay? I can't seem to find any indication in the HIG or else where this has been deprecated or discouraged.
Here's my code:
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"camera-navigation_item_back"]
style:UIBarButtonItemStyleBordered
target:nil
action:nil];
[navItem setBackBarButtonItem:barButtonItem];
iOS 7 Result:
iOS 6 Result:
EDIT: If I try to use one of the system items (plus sign, trash can, etc) as my back button, Apple substitutes the image for the title "Back." This is actually the same behavior in iOS 6 and 7.
Set the image's rendering mode to UIImageReneringModeAlwaysTemplate
(this topic is covered at around 33:00 in the WWDC video mentioned in the previous answer):
UIImage *backButtonImage = [UIImage imageNamed:@"imageName.png"];
backButtonImage = [backButtonImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UIBarButtonItem * backButton = [[UIBarButtonItem alloc]
initWithImage:backButtonImage
style:UIBarButtonItemStylePlain
target:nil
action:nil];
[[self navigationItem] setBackBarButtonItem:backButton];
[[[self navigationItem] backBarButtonItem] setTintColor:[UIColor redColor]];
The last line is not necessary if you have set the tintColor
globally in AppDelegate.h
:
[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]];