6

So as we know UINavigationController automatically presents Back button if new view controller was pushed to navigation controller's stack. If title was not set in previous view controller, back button shows default "Back" title. If I set title in previous view controller, back button shows that title. This is how it looks like:

Back title
Though sometimes, if that title is too long, back button title changes to the default "Back". It then looks like this:

enter image description here
That is expected behaviour and I'm fine with it.

The problem is that my app is localized to 3 different languages. I localize all controller's titles manually so when full title is shown in back button everything is fine.

The problem occurs when (localized) title is too long and it gets replaced with default "Back" title, which is in english (or default language, specified in iOS settings) and not in the language that my app currently shows.

So my question is how can I manually set back button title only when previous controller's title is too long?

I should add that I tried replacing default back button like that:

this.NavigationItem.BackBarButtonItem = new UIBarButtonItem (localizedBackTitle, UIBarButtonItemStyle.Plain, null);

It works fine, but back button title becomes 'static' and never shows the title of previous controller.

Andrius
  • 2,247
  • 3
  • 14
  • 15
  • If iOS is not properly localizing the "Back" label of the back button when your app is properly setup for localization, I would file a bug report with Apple. Include a sample app that demonstrates the issue. https://bugreport.apple.com – rmaddy Apr 07 '16 at 16:34
  • 1
    @rmaddy iOS is properly localizing "Back" label. The problem is that default language that users set in their settings app might be different than language in my app. I show screen where users can change language in my own app. It's the requirement that I have. – Andrius Apr 07 '16 at 16:41
  • That's different. You aren't using standard localization so it's not a bug really. – rmaddy Apr 07 '16 at 16:44
  • 1
    @rmaddy yes, I know its expected behaviour. I just want to replace default title of back button when it is shortened. – Andrius Apr 07 '16 at 16:51
  • Hi! I'm facing the same issue. Ever found a good solution for it? – Tiago Jan 02 '17 at 13:11
  • Unfortunately I haven't found a good solution for this. I believe I replaced back button's text to word 'Back' in each language. Now back button never shows title of previous controller but at least it is consistent. – Andrius Jan 02 '17 at 19:43
  • Would it not be possible to detect that the word Back has been used in place of the previous view controller's title and only then substitute a localized translation for Back? – Verticon Apr 27 '17 at 13:41

1 Answers1

5

iOS provides the localization for the fallback text when it is to long. You only need to tell iOS that you support the language like this:

<key>CFBundleLocalizations</key>
   <array>
     <string>en</string>
     <string>ja</string>
   </array>

See also: How to change UITabBarController More button's title?

Community
  • 1
  • 1
nerdmed
  • 111
  • 1
  • 6
  • That would word, but the thing is that I'm using custom localization i.e. iOS settings are set to, say, English, but I have custom menu in my own UI which allows users to select different language. – Andrius May 12 '17 at 14:15