Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change shortened back button title?

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.

like image 943
Andrius Avatar asked Apr 07 '16 16:04

Andrius


1 Answers

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?

like image 114
nerdmed Avatar answered Oct 23 '22 03:10

nerdmed