I'm pretty new to iOS development and I was asking my self if it is possible to use localized strings from my "Localizable.strings" file directly into the storyboard.
For example in Android you can do it from the XML file like this:
android:text="@string/notConnected"
I understood that you can make a localized version of the storyboard, but having different strings files and different storyboards looks pretty ugly to me.
So is it possible to have only strings files and use what I need into the storyboard? Preferably without setting it from code?
EDIT:
This is practically what I want to do:
So is this possible? Is there a legit way to call a string from there like in Android?
Best Answer
I think being able to localise
String
s in the storyboard is of significant advantage. I don't agree with @elk_cloner that hooking upIBOutlet
s for everyUILabel
is the way forward.One way of getting it to work is using an @IBInspectable property on a
UILabel
subclass:In the storyboard set the custom class:
In the attributes inspector the localisedKey field will appear and you can just add your key here.
That's it!
EDIT:
You can localise
UIButton
s the same way, BUT if the text in the storyboard's title field differs from the localised String (which it will in other languages) the setting of the title will animate.To fix this, put the setTitle in a
performWithoutAnimation
block: