在约束条件下以编程方式创建了UILabel。现在我想更新UILabel的高度限制

时间:2019-07-17 13:19:27

标签: ios swift iphone constraints uilabel

我的代码如下

movieDescLbl.translatesAutoresizingMaskIntoConstraints = false movieDescLbl.heightAnchor.constraint(equalToConstant: 87).isActive = true

我不确定如何以编程方式更新高度限制。

1 个答案:

答案 0 :(得分:1)

创建变量

var heightCon:NSLayoutConstraint!

分配

heightCon = movieDescLbl.heightAnchor.constraint(equalToConstant: 87)
heightCon.isActive = true

更新

heightCon.constant = 200
view.layoutIfNeeded()

OR

heightCon.isActive = true/false