Swiftstraints
Swiftstraints
can turn verbose auto-layout code:
Into one just one line of code:
Or transform your less than consise visual format language code:
Into the following:
That was easy!
Installation
Swiftstraints
is available through CocoaPods. To install, simply include the following lines in your podfile:
Be sure to import the module at the top of your .swift files:
Alternatively, clone this repo or download it as a zip and include the classes in your project.
Constraints
With Swiftstraints
you can create constraints that look just Apple's generic constraint definition:
Swifstraints
utilizes the new layout anchors introduced in iOS 9:
Swiftstraints
implements operator overloading so that you can easily create custom constraints:
Just as you would expect, you can specify a multiplier:
Or add a constant:
You can specify inequalities:
And you can define constant constraints if you so choose:
Swiftstraints can readily compute relatively complex constraints:
It's really easy.
Visual Format Language
Apple provides an API that lets you create multiple constraints simultaneously with the Visual Format Language. As we saw before it can be a little cumbersome:
Swiftstraints
uses string interpolation to let you specify the same constraints in one line of code:
Swiftstraints
also extends UIView
so that you can add constraints easily using the interpolated string format:
Super easy, super simple.
Revision History
- 3.0.1 - Bug fixes and limited iOS 8 support (Thank you catjia1011)
- 3.0.0 - Updated to Swift 3
- 2.2.0 - Added support for UILayoutPriority
- 2.1.0 - Fixed a view reference bug and added a new convenience method for adding constraints
- 2.0.2 - Added support for tvOS target.
- 2.0.1 - Updated to include support for axis anchors, increased test coverage and more documentation.
- 2.0.0 - Updated for Swift 2.0 and iOS 9. Now uses layout anchors for simple constraints and string interpolation for Visual Format Language constraints.
- 1.1.0 - Minor API tweaks
- 1.0.0 - Initial Release
Author
Brad Hilton, brad.hilton.nw@gmail.com
License
Swiftstraints is available under the MIT license. See the LICENSE file for more info.