How can I change the aspect ratio constraint value from code?

1.2k views Asked by At

I have given an aspect ratio constraint of 1:2 for an imageView in my xib. I have created an IBOutlet for the constraint. Now I need to change the aspect ratio to 1:1 for certain criteria. I want to know whether there is any way to change the constraint's multiplier value other than removing the old constraint and putting in a new one??

2

There are 2 answers

1
James On

I think its not possible other than the 'remove and replace constraint' method.

0
Nike Kov On

The multiplier is a get only property. So you can change only constant and isActive.

The constant for this constraint changes the height. If constant == width, then the height would be zero.

It's better to add height and width constraints and change them in code.