ViniciusDeep / delayout

An(other πŸ€·πŸ»β€β™‚οΈ) AutoLayout DSL to make constraints more quickly and with less verbosity.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Delayout

Swift

An(other πŸ€·πŸ»β€β™‚οΈ) AutoLayout DSL to make constraints more quickly and with less verbosity.

This is a project with the objective to learn more about iOS AutoLayout and make a tool in order to facilitate making constraints using a Domain Specifc Language (DSL).

This project it's based on Swift by Sundell article Building DSLs in Swift.

How it works?

In this first version I kept it simple just by encapsulating some AutoLayout methods to provide a simpler API.

// Using pure AutoLayout
label.translatesAutoresizingMaskIntoConstraints = false
label.topAnchor.constraint(equalTo: view.topAnchor, constant: 16).isActive = true
label.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16).isActive = true
label.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -16).isActive = true
label.heightAnchor.constraint(equalToConstant: 80).isActive = true
// The same visual behavior of above code, but using Delayout
label.layout {
    $0.top.equal(to: view.topAnchor, offsetBy: 16)
    $0.leading.equal(to: view.leadingAnchor, offsetBy: 16)
    $0.trailing.equal(to: view.trailingAnchor, offsetBy: -16)
    $0.height.equal(to: 80)
}
// You can even use some operators to write less code
label.layout {
    $0.top == view.topAnchor + 32
    $0.leading == view.leadingAnchor + 16
    $0.trailing == view.trailingAnchor - 16
    $0.height == 80
}

The idea is to improve this project more and more and launch it as a Swift Package soon so feedbacks and suggestions are welcome πŸ˜ŽπŸ‘πŸ».

License

This project is under the MIT license. See LICENSE for details.

About

An(other πŸ€·πŸ»β€β™‚οΈ) AutoLayout DSL to make constraints more quickly and with less verbosity.

License:MIT License


Languages

Language:Swift 100.0%