在代码中创建约束的最佳方式。
translatesAutoresizingMaskIntoConstraints
和约束激活。使用示例
// Core API
view.anchors.top.equal(superview.top)
view.anchors.width.equal(view.anchors.height * 2)
// Semantic API
view.anchors.edges.pin(insets: 20) // Pins to superview
view.anchors.edges.pin(to: superview.safeAreaLayoutGuide, insets: 20)
view.anchors.width.clamp(to: 10...40)
这里有一些更强大的东西
view.anchors.edges.pin(insets: 20, alignment: .center)
Align 的 文档 使用 DocC 创建,并以清晰直观的方式涵盖了所有 API。还有一个 速查表,其中列出了所有可用的 API。
Align | Swift | Xcode | 平台 |
---|---|---|---|
Align 3.3 | Swift 5.10 | Xcode 15.3 | iOS 14, tvOS 14, macOS 10.16 |
Align 3.0 | Swift 5.6 | Xcode 13.3 | iOS 12, tvOS 12, macOS 10.14 |
Align 遵循 Swift API 设计指南,力求清晰简洁。 尽管大多数 API 都很紧凑,但实现尽可能简洁的语法 *并非目标*。
Align 适合以下人群:
anchors