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

为君一笑 提交于 2021-02-07 20:23:11

问题


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??


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/30773182/how-can-i-change-the-aspect-ratio-constraint-value-from-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!