You can do this @IBDesignable and then implement prepareForInterfaceBuilder :
@IBDesignable public class MyUILabel: UILabel { public override func awakeFromNib() { super.awakeFromNib() configureLabel() } public override func prepareForInterfaceBuilder() { super.prepareForInterfaceBuilder() configureLabel() } func configureLabel() { font = UIFont(name: Constants.DefaultFont, size: 40) } }
Note. IB did not like it when I implemented init(coder:) , so I moved it to awakeFromNib .
Also note that when you create the @IBDesignable class, Apple advises creating a separate target (for example, "File" - "New" - "Target ..." - "Cocoa Touch Framework") for this conditional class. For more information, see WWDC 2014 Video What's New in Interface Builder .
source share