Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom image for UINavigation Back Button in iOS 7

I have a custom UIBarButtonItem with an image that works fine in iOS 6.1. But iOS 7 has a tintColor and it overlays this color over my image. If I set the tintColor to [UIColor clearColor] the button doesn't show up all together.

How can I have my back button show up in iOS 7 as it does in iOS 6? Please help?

iOS 6.1

iOS 7

like image 219
Majid Avatar asked Sep 20 '13 08:09

Majid


2 Answers

You should use appearance on UINavigationBar to globally set the custom back button.

[UINavigationBar appearance].backIndicatorImage = customBackButton;
[UINavigationBar appearance].backIndicatorTransitionMaskImage = customBackButton;
like image 91
Johannes Avatar answered Oct 17 '22 07:10

Johannes


Try to set UIBarButtonItem like this way in ios7:-

UIImage *temp = [[UIImage imageNamed:@"theImage"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];    
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithImage:temp style:UIBarButtonItemStyleBordered target:self action:@selector(action)];

Here is an original post in apple Dev center discussion Forums

For supporting both version iOS7 as well as lower then you check system-version and set code like:-

UIImage *temp=nil;

if([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0)
{ 
    temp = [UIImage imageNamed:@"btn-back.png"]; 
}
else
{ 
    temp = [[UIImage imageNamed:@"btn-back.png"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];
 }
like image 23
Nitin Gohel Avatar answered Oct 17 '22 06:10

Nitin Gohel