What I wanted to do is to remove the text from the 'Back' button of a UIBarButtonItem
, leaving only the blue chevron on the navigation bar. Keep in mind that I'm developing for iOS 7. I've tried several methods, including, but not limited to:
This is the image method which I did not like (the image looked out of place):
UIBarButtonItem *barBtnItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"iOS7BackButton"] style:UIBarButtonItemStylePlain target:self action:@selector(goToPrevious:)];
self.navigationItem.leftBarButtonItem = barBtnItem;
Another method I tried was this, which simply did not work (nothing was displayed):
UIBarButtonItem *barBtn = [[UIBarButtonItem alloc]init];
barBtn.title=@"";
self.navigationItem.leftBarButtonItem=barBtn;
What I wanted to achieve is something like the back buttons found in the iOS 7 Music app, which only featured a single chevron.
Thanks.
I didn't have a lot of success with the provided answers but I did find a really simple work around. In your storyboard, you can click on your UIViewController's Navigation Item and set the back button text. I set it to a single ' ' space and it gave me the behavior I was looking for.
You can also use this:
This works for me
I couldn't get it to work using Guto Araujo's answer of
navigationBar.topItem.title = @"";
However, I was able to get the desired effect by setting
self.title = @""
in theinit
method of my view controller. (Setting it ininit
is important,viewDidLoad
won't work.)To set the back button title for a view controller without changing its title use:
Objective-C:
Swift:
To be clear, this is done on the view controller that you would see if you hit the back button. i.e. instead of seeing '< Settings' you want to just see '<' then on your SettingsViewController you would put this in your
init
. Then you don't get any of the problems of the title not showing when you're looking at the view controller itself.SWIFT 3