I'm new to native iOS development, and have been playing with localizing storyboards.
I've been localizing the text for UILabel
and UIButton
objects in my storyboard by updating the Main.strings
files for the storyboard:
// UIButton:
"cEx-Yi-RY8.normalTitle" = "Done";
// UILabel:
"1l2-H9-hRc.text" = "Safety information!";
How do I do the same for a UITabBarItem
? I have tried:
//UITabBarItem:
"oSH-y1-hFoB.title" = "Scan";
But it doesn't work :(
I don't get why... I can see it is possible to update the text manually in the UITabBarController:
- (void)viewDidLoad
{
//...
item.title = NSLocalizedString(@"scan", nil);
}
But then I have to put those translations in a separate Localizable.strings
file, which seems lame.
On the other hand, at least the translations in Localizable.strings
are somewhat readable, i.e. "scan" = "Scan";
rather than "oSH-y1-hFoB.title" = "Scan";
...
Still... I'm not following why some stuff works in Interface Builder but other stuff doesn't and you have to do it manually.
I hate having to add all this boilerplate code to do repetitive stuff like localizing text in the UI, when the framework should just be able to do it for me. (If it can do it for a UIButton, why not a UITabBarItem...)
Or am I just overlooking something?
While you can localize UITabBarItem
s just like any other StoryBoard component, be aware that if you set a title for the associated view controller, it will overwrite the title of the UITabBarItem
. That will prevent your localizations from appearing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With