1:1 width:height 以编程方式约束 UIButton
1:1 width:height constraint to UIButton programmatically
如何在 swift 中以编程方式将 UIButton 上的纵横比约束设置为 1:1 比率 width:height?
此图在 Interface Builder 中显示了我想通过代码实现的目标。
试试这个
myButton.addConstraint(NSLayoutConstraint(item: myButton, attribute: .height, relatedBy: .equal, toItem: myButton, attribute: .width, multiplier: 1, constant: 0))
如何在 swift 中以编程方式将 UIButton 上的纵横比约束设置为 1:1 比率 width:height? 此图在 Interface Builder 中显示了我想通过代码实现的目标。
试试这个
myButton.addConstraint(NSLayoutConstraint(item: myButton, attribute: .height, relatedBy: .equal, toItem: myButton, attribute: .width, multiplier: 1, constant: 0))