测试已测试 | ✓ |
语言语言 | SwiftSwift |
许可 | MIT |
发布最后发布 | 2017年9月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 赵阳阳 维护。
AutoLayoutDSL-Swift 是一个简单的 swift DSL/扩展,用于更方便的自动布局管理
**内嵌框架需要最低部署目标为 iOS 8**
要使用针对 iOS 7 的项目中的 AutoLayoutDSL-Swift,您必须直接将位于
源目录
中所有 Swift 文件包含到您的项目中。有关其他说明,请参阅 ‘源文件’ 部分。
import AutoLayoutDSL-Swift
view.left == parentView.left + 10
// is equal to
NSLayoutConstraint(item: view, attribute: .Left, relatedBy: .Equal, toItem: parentView, attribute: .Left, multiplier: 1, constant:10
view.right >= parentView.right - 10
// is equal to
NSLayoutConstraint(item: view, attribute: .Right, relatedBy: .GreaterThanOrEqual, toItem: parentView, attribute: .Right, multiplier: 1, constant:- 10
view.height == anotherView.height * 2
// is equal to
NSLayoutConstraint(item: view, attribute: .Height, relatedBy: .Equal, toItem: anotherView, attribute: .Height, multiplier: 2, constant:0
view.height == anotherView.height / 2
// is equal to
NSLayoutConstraint(item: view, attribute: .Height, relatedBy: .Equal, toItem: anotherView, attribute: .Height, multiplier: 0.5, constant:0
view.height == 100
// is equal to
NSLayoutConstraint(item: view, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1, constant:100
// 4 NSLayoutConstraints were added and all their priority will be UILayoutPriorityRequired
self.view => self.redView.left == self.view.left + 10
=> self.redView.right == self.view.right - 10
=> self.redView.top == self.view.top + 30
=> self.redView.height == 100
// 4 NSLayoutConstraints were added
// First two constraints' priorities will be UILayoutPriorityRequired
// Third constraint‘s priority will be UILayoutPriorityDefaultHigh
// Fourth constraint's priority will be UILayoutPriorityDefaultLow
self.view => self.redView.left == self.view.left + 10
=> self.redView.right == self.view.right - 10
~~> self.redView.top == self.view.top + 30
~~~> self.redView.height == 100
// If you want custom priority, you can write as belowing
var constaint = self.redView.left == self.view.left + 10
constraint.priority = UILayoutPriorityDefaultHigh - 1
self.view => constraint // => doesn't change priority
如果您正在使用 Swift 编写 iOS 项目,并且您希望通过手动编写代码来创建 UI 而不是使用 Storyboard,但您仍然想利用 AutoLayout 的优势来节省框计算,并使用自动处理动态内容,AutoLayoutDSL-Swift 可以是您的一个选择,这样您就不需要编写很多代码来创建 NSLayoutConstraint 实例,还可以使代码更加简洁和直接。
AutoLayoutDSL-Swift受到AutoLayoutDSL的启发,然而AutoLayoutDSL是用Objective C++编写的。
AutoLayoutDSL-Swift采用MIT许可证发布。详细信息请参阅LICENSE文件。