When rendering in the Interface Builder (IB), the properties that are set to IB in the user interface of the user interface are loaded after the call init. Your installation code backgroundColoris initinvoked. But after that, he again sets the backgroundColorvalue backgroundColorto IB.
Apple . , . .
@IBDesignable class CustomLabel: UIView {
let view = UIView()
override var backgroundColor: UIColor? {
didSet {
print("here: ");
}
}
func setup() {
self.backgroundColor = UIColor.redColor()
view.backgroundColor = UIColor.greenColor()
view.frame = CGRect(x: 0, y: 0, width: 50, height: 50)
addSubview(view)
}
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}
}
. CustomLabel Interface Builder "" ➔ " ".
. , , .
, , , IB.
override func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
backgroundColor = UIColor.grayColor()
}