Skip to content

Latest commit

 

History

History
82 lines (55 loc) · 2.81 KB

README.md

File metadata and controls

82 lines (55 loc) · 2.81 KB

Curt

Build Status codecov

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 = true

Can be defined like:

viewA.topAnchor ~ viewB.bottomAnchor + 10

Installation

To 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)

Operators

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.

Operator ~

You can use it to constrain any kind of NSLayoutAnchor.

viewA.topAnchor ~ viewB.topAnchor
viewA.widthAnchor ~ viewB.widthAnchor
viewA.centerXAnchor ~ viewB.centerXAnchor
viewA.heightAnchor ~ 120

This operator can also be used to constrain all X and Y axis anchors at once

viewA ~ viewB

Operators <~ >~

This operators are the same but working as lessThanOrEqualTo and greaterThanOrEqualTo.

viewA.topAnchor >~ viewB.topAnchor
viewA.widthAnchor <~ viewB.widthAnchor
viewA.heightAnchor >~ 120

Operators + -

These operators are used to add the constant to any constraint.

viewA.topAnchor ~ viewB.bottomAnchor + 20
viewA.bottomAnchor ~ viewC.bottomAnchor - 20

Operator *

This operator is used to add the multiplier factor to any constraint.

viewA.widthAnchor ~ viewA.heightAnchor * 2.0 + 40

About

This 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.

Contribute

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.

License

Curt is available under the MIT license. See the LICENSE file for more info.