如何从代码中更改长宽比约束值? [英] How can I change the aspect ratio constraint value from code?
问题描述
我在xib中为imageView给出了1:2的宽高比约束.我已经为约束创建了一个IBOutlet.现在,我需要将某些标准的宽高比更改为1:1.我想知道除了删除旧约束并放入新约束之外,是否还有其他方法可以更改约束的乘数?
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??
推荐答案
乘数是仅获取属性.因此,您只能更改常量和isActive.
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.
这篇关于如何从代码中更改长宽比约束值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!