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 was having a same problem and I did it this way.
--EDIT--
this is a solution when you really want to remove title text of all UIBarbuttonItem. If you only want to remove the title of the back bar button item, there is no one simple convenient solution. In my case, since I only have few UIBarButtonItems that need to show title text I just changed those specific buttons' titleTextAttributes. If you want to be more specific use the code below, which will only change navigation bar buttons:
Here's what I'm doing me, which is simpler to remove the title of back button
Then you can remove the back button item title.
If you use Storyboard, you can set navigation attributes inspector Back Button with space.
Simple solution to this problem, working on iOS7 as well as 6, is to set custom title view in viewDidLoad:
Then, in viewWillAppear: you can safely call
Because your title view is custom view, it won't get overwritten when moving back in the navigation stack.
In the prepareForSegue: method of your first ViewController you set that views title to @"", so when the next view is pushed it will display the previous ViewController title which will be @"".
The only problem with this is that when you hit the back button your previous view won't have a title, so you may add it again on viewWillAppear:
I don't like very much this solution but it works and i didn't find other way to do it.