为约束设置标识符更好更容易,如下面的屏幕截图所示,并使用以下
if let topConstraint = button.constraints.first(where: { $0.identifier == "topConstraint" }) {
... use topConstraint
}
Run Code Online (Sandbox Code Playgroud)
其它的办法:
if let topConstraint = button.constraints.first(where: { ($0.firstAttribute == .top && $0.firstItem === button) || ($0.secondAttribute == .top && $0.secondItem === button) }) {
... use topConstraint
}
Run Code Online (Sandbox Code Playgroud)
小智 5
你可以用 3 种方式做到
{view}.constraints.filter { $0.firstAttribute == .leading }
Run Code Online (Sandbox Code Playgroud)
{view}.constraints.filter { $0.identifier == "your identifier" }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2105 次 |
| 最近记录: |