Curt is a collection of Swift operators to make constraints setup faster to write and easier to read.
Using Curt, constraints like:
viewA.topAnchor.constraint(equalTo: viewB.bottomAnchor, constant: 10).isActive = trueCan be defined like:
viewA.topAnchor ~ viewB.bottomAnchor + 10To install Curt you have to add the Curt.swift file to your project.
Since operator overloading can't be done in a separate module Curt can't be added to you project using solutions like cocoapods or carthage. (We are investigating solutions for this)
These are the Curt operators and some examples, check out the tests to see all the cases and examples between Curt and Native API. All the operators return activated NSLayoutConstraint.
You can use it to constrain any kind of NSLayoutAnchor.
viewA.topAnchor ~ viewB.topAnchor
viewA.widthAnchor ~ viewB.widthAnchor
viewA.centerXAnchor ~ viewB.centerXAnchor
viewA.heightAnchor ~ 120This operator can also be used to constrain all X and Y axis anchors at once
viewA ~ viewBThis operators are the same but working as lessThanOrEqualTo and greaterThanOrEqualTo.
viewA.topAnchor >~ viewB.topAnchor
viewA.widthAnchor <~ viewB.widthAnchor
viewA.heightAnchor >~ 120These operators are used to add the constant to any constraint.
viewA.topAnchor ~ viewB.bottomAnchor + 20
viewA.bottomAnchor ~ viewC.bottomAnchor - 20This operator is used to add the multiplier factor to any constraint.
viewA.widthAnchor ~ viewA.heightAnchor * 2.0 + 40This project is funded and maintained by Caramba. We 💛 open source software!
Check out our other open source projects, read our blog or say 👋 on twitter @carambalabs.
Contributions are welcome 🤘 We encourage developers like you to help us improve the projects we've shared with the community. Please see the Contributing Guide and the Code of Conduct.
Curt is available under the MIT license. See the LICENSE file for more info.