Custom image for UINavigation Back button in iOS 7

I have a custom UIBarButtonItem image that works fine in iOS 6.1. But iOS 7 has tintColor and imposes this color on my image. If I set tintColor to [UIColor clearColor] , the button will not be displayed together.

How can I open my button in iOS 7, like in iOS 6? Please, help?

iOS 6.1

iOS 7

+31
ios objective-c iphone ios6 ios7
Sep 20 '13 at 8:57
source share
6 answers

Try installing UIBarButtonItem as follows in ios7: -

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

Here is the original post in apple dev center discussion forums

To support both version iOS7 and below, you check the system-version and install the code as follows: -

 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]; } 
+22
Sep 20 '13 at 9:15
source share

You must use the look and feel in the UINavigationBar to globally set a custom back button.

 [UINavigationBar appearance].backIndicatorImage = customBackButton; [UINavigationBar appearance].backIndicatorTransitionMaskImage = customBackButton; 
+37
Apr 29 '15 at 8:02
source share

The following is apparently a little more useful for people who don't want to mess with an existing target action, etc. Just copy and paste. In addition, it makes iOS use your image with all its trays - as opposed to just using a template / image experience.

 - (void)setCustomNavigationBackButton { UIImage *backBtn = [UIImage imageNamed:@"arrow"]; backBtn = [backBtn imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; self.navigationItem.backBarButtonItem.title=@""; self.navigationController.navigationBar.backIndicatorImage = backBtn; self.navigationController.navigationBar.backIndicatorTransitionMaskImage = backBtn; } 

arrow is the name of your image.

+20
Aug 07 '14 at 21:34
source share

Try this:

 self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:nil action:nil]; self.navigationController.navigationBar.backIndicatorImage = [UIImage imageNamed:@"yourImageName.png"]; self.navigationController.navigationBar.backIndicatorTransitionMaskImage = [UIImage imageNamed:@"yourImageName.png"]; 

This will create an image mask in the global color of the hue, which will give you your own icon. Does not work for color images.

+6
Jan 31 '14 at 10:58
source share

quick version:

 var backBtn = UIImage(named: "return_menu") backBtn = backBtn?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal) self.navigationController!.navigationBar.backIndicatorImage = backBtn; self.navigationController!.navigationBar.backIndicatorTransitionMaskImage = backBtn; 
+6
Jul 26 '15 at 7:55
source share

// ADD IMAGE TO THE BUTTON

 UIButton *refreshButton = [UIButton buttonWithType:UIButtonTypeCustom]; [refreshButton setFrame:CGRectMake(0,0,30,30)]; refreshButton.userInteractionEnabled = YES; [refreshButton setImage:[UIImage imageNamed:@"yourimage.jpg"] forState:UIControlStateNormal]; // ASSIGNING THE BUTTON WITH IMAGE TO BACK BAR BUTTON UIBarButtonItem *refreshBarButton = [[[UIBarButtonItem alloc] initWithCustomView:refreshButton] autorelease]; self.navigationItem.leftBarButtonItem = refreshBarButton; 
0
Sep 20 '13 at 10:07 on
source share



All Articles