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.
Perfect solution globally
This worked for me in iOS10. Call this from viewDidLoad of the view controller.
Non of the answers helped me. But a trick did - I just cleared the title of the view controller that pushed (where the back button is going to) just before pushing it.
So when the previous view doesn't have a title, on iOS 7 the back button will only have an arrow, without text.
On
viewWillAppear
of the pushing view, I placed back the original title.Hide Back Button Title of Navigation Bar
On iOS7, Apple introduced two new properties to UINavigationBar, 'backIndicatorTransitionMaskImage' and 'backIndicatorImage'.
By simply calling once:
It will render a custom image instead of the default chevron glyph, inheriting the keyWindow's tint color.
And for removing the title, I'll suggest Kamaros's answer. Remember to call this code on the view controller that's pushing your new view controller. Removing the title text of an iOS UIBarButtonItem