IBDesignable and prepareForInterfaceBuilder for NSLayoutConstraint?

I will subclass NSLayoutConstraintto provide custom spacing depending on the flag. Is it possible for this to be reflected in Interface Builder? I tried using IBDesignableand prepareForInterfaceBuilder, but it does not affect NSLayoutConstraintin the interface builder (it only reflects at run time).

Here is what I am trying:

@IBDesignable
class CustomLayoutConstraint: NSLayoutConstraint {

    @IBInspectable var doubleConstant: Bool = false

    override func awakeFromNib() {
        super.awakeFromNib()
        handleSelection()
    }

    override func prepareForInterfaceBuilder() {
        handleSelection()
    }

    func handleSelection() {
        if doubleConstant {
            constant *= 2
        }
    }
}

I have a flag in IBInspectablewhich will double the constant at runtime if it is set. Is there a way for this to reflect on the StoryBoard so that it is clear that something will happen?

+4
source share

All Articles