How can I customize the navigation back button in iOS 7 and above without title? (i.e. with the arrow only)
self.navigationItem.leftBarButtonItem = self.editButtonItem;
I'm just wondering if they have any self.backButtonItem;
OR
something like this?
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemBACK
target:self action:@selector(back)];
Create a
UILabel
with the title you want for your root view controller and assign it to the view controller'snavigationItem.titleView
.Now set the title to an empty string and the next view controller you push will have a back button without text.
I applied the following code in viewDidLoad and it works:
Just to update I use Vector Icon
EDIT: 2014-04-09: As I gained reputations, I feel sorry because I don't use this trick any more. I recommend Kyle's answer. Also notice that the
self
ofself.navigationItem.backBarButtonItem
isn't the view controller the back button is displayed, but the previous view controller to be went back.If you don't need to have title text for the previous view controller, just fill the title with a blank string;
This will prevent showing "back" with chevron on the pushed view controller.
EDIT: Even you use non-blank title text, setting the title of the previous view controller in
viewWillAppear:
works except the title can flicker in a blink when view controller popped. I think "The twitter app" seems to do more subtle hack to avoid the flicker.The only way that worked for me was:
UPDATE:
When I changed the segue animation flag to true (It was false before), the only way that worked for me was:
I found an easy way to make my back button with iOS single arrow.
Let's supouse that you have a navigation controller going to ViewA from ViewB. In IB, select ViewA's navigation bar, you should see these options: Title, Prompt and Back Button.
ViewA navigate bar options
The trick is choose your destiny view controller back button title (ViewB) in the options of previous view controller (View A). If you don't fill the option "Back Button", iOS will put the title "Back" automatically, with previous view controller's title. So, you need to fill this option with a single space.
Fill space in "Back Button" option
The Result:
Just like Kyle Begeman does, you add the code above at your root view controller. All the sub view controller will be applied. Additionally, adding this in initWithCoder: method, you can apply the style for root view controllers in xib, storyboard or code based approaches.