如何以编程方式更新UIView的恒定高度约束? [英] How to update the constant height constraint of a UIView programmatically?

查看:45
本文介绍了如何以编程方式更新UIView的恒定高度约束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIView,我使用Xcode Interface Builder设置了约束.

I have a UIView and I set the constraints using Xcode Interface Builder.

现在,我需要以编程方式更新该UIView's高度常数.

Now I need to update that UIView's height constant programmatically.

有一个类似于myUIView.updateConstraints()的功能,但我不知道如何使用它.

There is a function that goes like myUIView.updateConstraints(), but I don't know how to use it.

推荐答案

从界面"构建器中选择高度约束,并获取其出口.因此,当您要更改视图的高度时,可以使用以下代码.

Select the height constraint from the Interface builder and take an outlet of it. So, when you want to change the height of the view you can use the below code.

yourHeightConstraintOutlet.constant = someValue
yourView.layoutIfNeeded()

方法updateConstraints()UIView的实例方法.以编程方式设置约束时,这将很有帮助.它更新视图的约束.有关更多详细信息,请单击此处.

Method updateConstraints() is an instance method of UIView. It is helpful when you are setting the constraints programmatically. It updates constraints for the view. For more detail click here.

这篇关于如何以编程方式更新UIView的恒定高度约束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆