Today the multiplier
property is read-only. In order to change it, you have to remove the constraint and create a new one.
let newConstraint = NSLayoutConstraint(
item: constraint.firstItem,
attribute: constraint.firstAttribute,
relatedBy: constraint.relation,
toItem: constraint.secondItem,
attribute: constraint.secondAttribute,
multiplier: newMultiplier,
constant: constraint.constant
)
In this example, first the multiplier will be applied and then the constant. For example:
Imagine it's a width constraint to the superview.
This means we'll have view.width = superview.width * multiplier - 2
.
(which also means that a multiplier = 0
will break).
What I need is view.width = (superview.width - 2) * multiplier
. How do I create such constraint?
I also don't want to do something like:
let newConstraint = NSLayoutConstraint(
item: constraint.firstItem,
attribute: constraint.firstAttribute,
relatedBy: constraint.relation,
toItem: constraint.secondItem,
attribute: constraint.secondAttribute,
multiplier: newMultiplier,
constant: constant * newMultiplier
)
Because I end up losing the constraint.constant
that comes from the storyboard.