答案 0 :(得分:1)
您可以通过3种方式完成
{view}.constraints.filter { $0.firstAttribute == .leading }
{view}.constraints.filter { $0.identifier == "your identifier" }
答案 1 :(得分:0)
设置约束的标识符更好,并且更容易,如下面的屏幕截图所示,并使用以下命令
if let topConstraint = button.constraints.first(where: { $0.identifier == "topConstraint" }) {
... use topConstraint
}
另一种方式:
if let topConstraint = button.constraints.first(where: { ($0.firstAttribute == .top && $0.firstItem === button) || ($0.secondAttribute == .top && $0.secondItem === button) }) {
... use topConstraint
}