-2

I have the back buttons translated to german ("Zurück"). However, it seems that when there isn't enough space (because of the length of the title) it is shown as "back". And if there is only very little space, no title is shown at all, only the chevron "<".

Is there a way for it to not show the back buttons with the "back" title, but only as "<" if there isn't enough space for "Zurück"?

Daniel
  • 20,420
  • 10
  • 92
  • 149

2 Answers2

2

You can override loadView and put this code in your view controller:

self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];

You could calculate the text length before that in order to decide if you want to show the back button with title or without it.

Edit

It's better to do this in a UIViewController superclass and have all your view controllers extend that class.

amb
  • 4,798
  • 6
  • 41
  • 68
  • As described [here](http://stackoverflow.com/a/11031426/386738). It would also set the title of subviews. Which means I would have to do it on every single `UIViewController`. Isn't there a way where I only have to do it on the first UIViewControllers? (I have a lot, and I'm lazy) – Daniel Feb 18 '15 at 10:02
  • @simpleBob you can create a subclass of ``UIViewController``, make all your view controllers subclass of that class and implement the logic once in your parent class (override ``loadView`` or ``viewWillAppear`` and put your logic there). – amb Feb 18 '15 at 10:16
0
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
                                                             forBarMetrics:UIBarMetricsDefault];

Then you can remove the back button item title.

If you use Storyboard, you can set navigation attributes inspector Back Button with space.

You can follow this link

Community
  • 1
  • 1
  • Appearance proxy modifies all the ``UIBarButtonItem`` back button instances, and thus you cannot have the condition to decide to hide or not the back button text. – amb Feb 18 '15 at 09:49
  • I want to show the translated button title if there is enough space – Daniel Feb 18 '15 at 09:59