An attempt to simplify creating AutoLayout constraints.
This package includes two approaches: Extensions and Custom Opterators.
WARNING: It's still WIP and mostly untested.
Simplifying the API by removing the redundant (arumgent)names:
// BEFORE
view.topAnchor.constraint(equalTo: other.topAnchor, constant: 5.0)
// AFTER
view.topAnchor.equalTo(other.topAnchor, 5.0)
A more visual approach: anchor <assignment> (anchor or expression)
Operator | Equivalent |
---|---|
|==| |
equalTo... |
|<=| |
lessThanOrEqualTo... |
|>=| |
greaterThanOrEqualTo...) |
Operator | Equivalent |
---|---|
|=~| |
equalToSystemSpacing... |
|<~| |
lessThanOrEqualToSystemSpacing... |
|>~| |
greaterThanOrEqualToSystemSpacing...) |
Operator | Equivalent |
---|---|
+ |
Constant (right-side only) |
- |
Negative constant (right-side only) |
* |
Multiplier (left-side only) |
Operator | Right-hand-side type | Action |
---|---|---|
~~ |
UILayoutPriorty /Float |
Sets .priority |
~~ |
String |
Sets .identifier |
// BEFORE
let constraint = left.rightAnchor.constraint(equalsTo: right.leftAnchor, constant: 8.0)
constraint.priority = .required
constraint.identifier = "Left-To-Right"
// AFTER
let constraint = left.rightAnchor |==| right.leftAnchor + 8.0 ~~ .required ~~ "Left-To-Right"
MIT. See LICENSE.md