2

Make a UIView with a fixed height constraint, notice I set it to say 40 in IB.

Change the constraint class to this:

@IBDesignable class BadassHeightConstraint: NSLayoutConstraint {

    override var constant: CGFloat {
        set {
            super.constant = newValue
        }
        get {
            return calc()
        }
    }

    private func calc() -> CGFloat {
        return 100.0
    }
}

This works perfectly at runtime, left image, it's 100, not 40.

But, I cannot get it to work in IB. Why is this so?

enter image description here

Is there any solution to have these work in IB?

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Fattie
  • 27,874
  • 70
  • 431
  • 719

1 Answers1

2

Putting it simply, only a UIView can be @IBDesignable.

matt
  • 515,959
  • 87
  • 875
  • 1,141