I'm trying to implement a localizable class for UIButtons using live rendering in the Interface Builder. This is the code I have so far:
@IBDesignable class TIFLocalizableButton: UIButton {
@IBInspectable var localizeString:String = "" {
didSet {
#if TARGET_INTERFACE_BUILDER
var bundle = NSBundle(forClass: self.dynamicType)
self.setTitle(bundle.localizedStringForKey(self.localizeString, value:"", table: nil), forState: UIControlState.Normal)
#else
self.setTitle(self.localizeString.localized(), forState: UIControlState.Normal)
#endif
}
}
}
The layout is correctly updating in the IB, but the text isn't showing up. I've created the same implementation with UILabel's which does work: https://github.com/AvdLee/ALLocalizableLabel
Any ideas on how to fix this are welcome!
At WWDC I was able to ask one of the engineers. Turns out to be fixed in this way:
As the interface builder calls the setTitle multiple times for different states.