简体   繁体   English

如何从代码中更改宽高比约束值?

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

I have given an aspect ratio constraint of 1:2 for an imageView in my xib. 对于xib中的imageView,我给出了1:2的宽高比约束。 I have created an IBOutlet for the constraint. 我为约束创建了一个IBOutlet。 Now I need to change the aspect ratio to 1:1 for certain criteria. 现在我需要将宽高比改为1:1以满足某些标准。 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?? 我想知道是否有任何方法可以更改约束的乘数值,而不是删除旧约束并放入一个新约束?

我认为除了'删除和替换约束'方法之外,它是不可能的。

The multiplier is a get only property. 乘数是唯一的属性。 So you can change only constant and isActive. 所以你只能改变常量和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. 最好添加高度和宽度约束并在代码中更改它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM