Make trains of constraints with style!
button.constren
.centerY()
.lead(spacing: 16)
.trail(image.leadingAnchor, spacing: 64)
.height(100, relation: .greaterThan)
Constren is an easy to use layout tool for UIKit
- iOS 10.0+
- Xcode 10.0+
- Swift 4.0+
To add Constren into your project using CocoaPods, add it in your Podfile:
pod 'Constren', :git => 'https://github.com/dorvk/Constren.git'
To add Constren into your project using Carthage, specify it in your Cartfile:
github "dorvk/Constren"
To add Constren into your project using Swift Package Manager, add following into your Package.swift file,
dependencies: [ .package(url: "https://github.com/dorvk/Constren.git", .branch("master")) ]
Add the Sources folder into your project.
import Constren
let imageView = UIImageView()
view.addSubview(imageView)
imageView.constren
.top() // default is equalToSuperview with 0 spacing
.lead(spacing: 16) // you can add spacing
.trail(label.leadingAnchor, spacing: 16)
.height(100, relation: .greaterThan) // supports lessThan or greaterThan, default is equalTo
var constraint = imageView.constren
.width(50)
.asNSLayoutConstraint
constraint?.constant = 100 // supports constant updating
tableView.constren.fill() // shortcuts
collectionView.constren.fill(lead: 16, bot: 32)
titleLabel.constren
.horizontalFill(lead: 16)
.centerY(spacing: 16)
imageView.constren
.centered(x: 16)
.squared(250)