I have a @IBDesignable
UIView
(ContainerView) that has one subView (also @IBDesignable
). I would very much like to be able to update the constraints of the subView in the code in a way were they are automatically updated in InterfaceBuilder.
Example:
@IBDesignable class ContainerView: UIView {
@IBOutlet var mySubView: MyView!
override func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
self.setup()
}
override func layoutSubviews() {
super.layoutSubviews()
self.setup()
}
private func setup() {
self.mySubView.leadingConstraint.constant = MyResource.sizes.defaultLeading
}
}
This will work just fine at runtime, but it crashes the IBDesignablesAgent
because mySubView
is nil
when running prepareForInterfaceBuilder
.
I want to do it this way to be able to set my constraints globally in some constants, but keep the view representation in my xib files.
Does anyone have a work around for this, or am I reaching for the impossible here?