向 UILabel 问题添加高度约束
Adding height constraint to UILabel issue
在 Swift3 中,我想给 UILabel 添加 20px 的高度约束,但没有成功,我缺少什么?
addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .height, relatedBy: .equal, toItem: self, attribute: .height, multiplier: 1, constant: 20))
此代码适用于 Swift2。
谢谢。
一种直接的方式:
// assuming your UILabel is myLabel
myLabel.heightAnchor.constraint(equalToConstant: 20.0).isActive = true
在 Swift3 中,我想给 UILabel 添加 20px 的高度约束,但没有成功,我缺少什么?
addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .height, relatedBy: .equal, toItem: self, attribute: .height, multiplier: 1, constant: 20))
此代码适用于 Swift2。
谢谢。
一种直接的方式:
// assuming your UILabel is myLabel
myLabel.heightAnchor.constraint(equalToConstant: 20.0).isActive = true