使用约束以编程方式创建 UILabel。现在我想更新 UILabel 的高度限制

Created UILabel programmatically with constraints. Now i want to update the height constraints of the UILabel

我的代码如下

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

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

创建变量

var heightCon:NSLayoutConstraint!

分配

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

更新

heightCon.constant = 200
view.layoutIfNeeded()

heightCon.isActive = true/false