const is a (another) type-safe and expressive Swift DSL for Auto Layout
Example
let topView = UIView()
topView.backgroundColor = .red
baseView.addSubview(topView)
let bottomView = UIView()
bottomView.backgroundColor = .blue
baseView.addSubview(bottomView)
topView.constraints { make in
make.top.equalTo(.superview).withInset(50)
make.left.equalTo(.superview).withInset(50)
make.right.equalTo(.superview).withInset(50)
make.bottom.equalTo(.centerY, of: .superview).withInset(25)
}
bottomView.constraints { make in
make.top.equalTo(.bottom, of: .view(topView)).withOffset(50)
make.left.equalTo(.superview).withInset(50)
make.right.equalTo(.superview).withInset(50)
make.bottom.equalTo(.superview).withInset(50)
}
This code produces the following result:
Features
-
Lightweight — the current version of const consists of less than 500 lines of code. Although this project may become larger with time, it's very unlikely that it will exceed 1000 lines
-
Familiar and expressive — const API is heavily inspired by SnapKit, so if you have any experience with it, you shouln't have any problems getting familiar with this library
-
Pure Swift — that's it. No Objective-C code or using any of its runtime features like associated objects
Installation
You can install const using CocoaPods:
pod 'Const', '~> 0.1'
Or using Swift Package Manager:
.package(url: "https://github.com/acedened/const.git", from: "0.1.0")