6
votes

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.

1
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. bugreport.apple.comrmaddy
@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
That's different. You aren't using standard localization so it's not a bug really.rmaddy
@rmaddy yes, I know its expected behaviour. I just want to replace default title of back button when it is shortened.Andrius
Hi! I'm facing the same issue. Ever found a good solution for it?Tiago

1 Answers

5
votes

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?