Swiftpack.co - dehesa/Autolayout as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by dehesa.
dehesa/Autolayout 2.0.0
Non verbose way to create constraints and work with anchors
⭐️ 2
🕓 39 weeks ago
iOS macOS tvOS
.package(url: "https://github.com/dehesa/Autolayout.git", from: "2.0.0")

Logo & Name

Non verbose way to create constraints and work with anchors.

Swift 5.8 platforms License

This framework provides:

  • Operators (custom and overloads) for anchors and constraints. Let you define constraints simply and clearly.
    view.topAnchor == superview.topAnchor ~ .high + 10
    
    It also lets you store the constraint after definition.
    let constraint = view.topAnchor == superview.topAnchor ~ .high ↑ "CustomIdentifier"
    
  • Anchor groups. Autolayout provide group of anchors that usually perform similar operations. Such as horizontal anchors (left, right), directional anchors (leading, trailing), edge anchors (top, left, bottom, right), etc.
    scrollview.edgeAnchor == superview.edgeAnchor
    
    It lets you work with anchor groups similarly than you would work with simple anchors.
    scrollview.edgeAnchor == superview.edgeAnchor + 5 ~ .low
    
  • Constraint containers. It let you store or access easily constraints created through anchor groups.
    let container = view.directionalEdgeAnchor >= superview.directionalEdgeAnchor + 3 ~ .required
    container.leading.constant = 10
    container.bottom.isActive = true
    
    Autolayout lets you perform normal constraint operations on the whole constraint container.
    container.constant = 10
    
  • Compile-time constraint creation checks. You can only perform operations on compatible types. For example, none of following lines will compile:
    view.horizontalAnchor == superview.directionalAnchor
    view.sizeAnchor >= superview.verticalAnchor
    

License

This code and tool is under the MIT License. See LICENSE file in this repository.

Any ideas and contributions welcome!

Disclaimer

This framework was initially influenced by Anchorage by Raizlabs. Although the syntax is similar, Autolayout provide a completely different internals and generics system to facilitate compile-time checks and group operations (such as activity or constant settings).

In any case, Anchorage is still a great tool that I thoroughly recommend to anyone ;)

GitHub

link
Stars: 2
Last commit: 39 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Swift 5.8
39 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics