I am trying to use a custom item for the back button in my navigation bar.
UIImage *backButtonImage = [UIImage imageNamed:@"backbutton.png"];
UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithImage:backButtonImage style:UIBarButtonItemStylePlain target:nil action:nil];
[self.navigationItem setBackBarButtonItem: customItem];
[customItem release];
What I end up getting is my image with a border around it. It looks like this (My image is the back button):
How can I get rid of the border? What am I doing wrong?
Your image is appearing inside of a back button and it is apparently (from your screenshot) not the same size as the back button.
You might want to hide the back button and then replace it with a "Left Bar Button" instead.
Code:
Here's an updated version. This includes the setting the target, font size, etc.
Also, it reflects that
setHidesBackButton
is not available as a property ofnavigationController
.Note that this is from an ARC project, so no releases etc. on the objects.
I created a category of UINavigationBar which I call in viewWillAppear in each of my viewControllers. The code that I use to change the appearance of my back button is the following:
Works perfectly under iOS 6.
Building on Jorge's code, this is my solution.
I create a simple category on
UIViewController
:UIViewController+ImageBackButton.h
UIViewController+ImageBackButton.m
Now all you have to do is
#import UIViewController+ImageBackButton.h
in either all of your view controllers or in a custom base view controller class that your other view controllers inherit from and implement theviewWillAppear:
method:That's all. Now you have an image back button everywhere. Without a border. Enjoy!