UIStoryboards, IBDesignable and localization

One of the important parts in building apps is localization. It’s something we developers mostly postpone till the end of the development process. Making this process easier would make it more accessible to do it more constantly during the project, which can be done using IBDesignable and IBInspectable properties.

Xcode 6 introduced these properties, which makes it possible to add properties to IBObjects. An extension to UILabels with IBDesignable properties makes it possible to enter a localization string and localise directly within the interface builder.

IBDesignable and IBInspectable usage example

The class looks as followed:

@IBDesignable class ALLocalizableLabel: UILabel {

    @IBInspectable var localizeString:String = "" {
        didSet {
                var bundle = NSBundle(forClass: self.dynamicType)
                self.text = bundle.localizedStringForKey(self.localizeString, value:"", table: nil)
                self.text = NSLocalizedString(self.localizeString, comment:"");

And results in the following option:
UILabel localization in interface builder using IBDesignable

Make localization easier! Get the code from Github:


Antoine van der Lee

Dutch iOS developer at Triple. Developed apps like Buienradar, Videoland and Pop the Dots.

Follow on Feedly