I want to be able to set the title of my custom control in interface builder and implement the title as a UILabel. I have created my properties thus:
@IBInspectable var titleText: String? {
get {
return title.text
}
set(newTitleText) {
title.text = newTitleText
}
}
@IBInspectable lazy var title: UILabel = UILabel.init()
Is this a good/recommended way to do this? I also want the control to layout the UILabel if the title text has been set and plan to do this by overriding layoutSubviews - again is this recommended or would you suggest a different pattern?
My ultimate aim is to be able to enable a designer to configure my control from IB and exposing the UILabel as a property that can be configured in IB would be my ideal.
@IBInspectablecan be used only with the following types:So, no, you can not "expose a
UILabel" for design-time manipulation.