SuperLayout is a Swift library that makes using Auto Layout a breeze.
Switch branches/tags
Nothing to show
Clone or download
Latest commit 462a8b9 Sep 30, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
.bundle update bundle config May 7, 2018
Sources minor cleanup Jan 24, 2017
SuperLayout.xcodeproj minor xcode project update Sep 30, 2018
Tests update tests Jan 24, 2017
docs documentation update Sep 30, 2018
meta update README Feb 23, 2018
.gitignore unignore xcodeproj Mar 10, 2018
.jazzy.yaml documentation update Sep 30, 2018
.ruby-version add Gemfile Mar 9, 2018
.travis.yml add linting Jan 24, 2017
Gemfile add Gemfile Mar 9, 2018
Gemfile.lock update Gemfile May 7, 2018
LICENSE add LICENSE file and swift version Jan 23, 2017
Makefile condense scripts into Makefile Mar 9, 2018
NOTICE add NOTICE Sep 17, 2017
Package.swift initial commit Jan 23, 2017 Update Feb 23, 2018
SuperLayout.podspec update swift version Sep 30, 2018
new1.png renames Jan 24, 2017
old1.png renames Jan 24, 2017

CI Status Version License Platform

SuperLayout is a library that adds a few custom operators to Swift that makes using the amazing NSLayoutAnchor API for Auto Layout a breeze. SuperLayout doesn't override already-defined methods in Equatable (such as == and >=), and defines ones that are logical and easily understandable to anyone who might be inheriting your codebase or joining your team.

What It Does

In short, SuperLayout turns this:

Into this:

How it works

SuperLayout defines three custom operators: ~~, ≥≥, and ≤≤ that correspond to equalTo, to greaterThanOrEqualTo, and to lessThanOrEqualTo, respectively.

The greater than and less than operators were chosen with practicality in mind; and have simple keyboard shortcuts (just Option + < and Option + > in macOS), so there's no need to copy-paste characters when writing constraints.


SuperLayout is available via CocoaPods and SwiftPM. If you're using CocoaPods, just specify this in your Podfile:

pod 'SuperLayout'

Before You Use

To use this library, you should have a basic understanding of the NSLayoutAnchor API. If not, read up, and then check out the documentation below to get started.

NSLayoutConstraint Reference

Note: SuperLayout does not (yet) automatically turn off translatesAutoresizingMaskIntoConstraints for the views you'd like to manage with Auto Layout. Disabling this setting automatically is too magical for me. Feel free to create an issue if you disagree.

constraint(equalTo:)viewA.rightAnchor ~~ viewB.leftAnchor

viewA.rightAnchor.constraint(equalTo: viewB.leftAnchor).isActive = true

constraint(equalTo:constant:)viewA.rightAnchor ~~ viewB.leftAnchor + C

viewA.rightAnchor.constraint(equalTo: viewB.leftAnchor, constant: C).isActive = true

constraint(greaterThanOrEqualTo:)viewA.rightAnchor ≥≥ viewB.leftAnchor

viewA.rightAnchor.constraint(greaterThanOrEqualTo: viewB.leftAnchor).isActive = true

constraint(greaterThanOrEqualTo:constant:)viewA.rightAnchor ≥≥ viewB.leftAnchor + C

viewA.rightAnchor.constraint(greaterThanOrEqualTo: viewB.leftAnchor, constant: C).isActive = true

constraint(lessThanOrEqualTo:)viewA.rightAnchor ≤≤ viewB.leftAnchor

viewA.rightAnchor.constraint(lessThanOrEqualTo: viewB.leftAnchor).isActive = true

constraint(lessThanOrEqualTo:constant:)viewA.rightAnchor ≤≤ viewB.leftAnchor + C

viewA.rightAnchor.constraint(lessThanOrEqualTo: viewB.leftAnchor, constant: C).isActive = true

NSLayoutDimension Reference

constraint(equalTo:multiplier:)viewA.heightAnchor ~~ viewB.heightAnchor * M

viewA.heightAnchor.constraint(equalTo: viewB.heightAnchor, multiplier: M).isActive = true

constraint(equalTo:multiplier:constant:)viewA.heightAnchor ~~ viewB.heightAnchor * M + C

viewA.heightAnchor.constraint(equalTo: viewB.heightAnchor, multiplier: M, constant: C).isActive = true

constraint(equalToConstant:)viewA.heightAnchor ~~ C

viewA.heightAnchor.constraint(equalToConstant: C).isActive = true

constraint(greaterThanOrEqualTo:multiplier:)viewA.heightAnchor ≥≥ viewB.heightAnchor * M

viewA.heightAnchor.constraint(greaterThanOrEqualTo: viewB.heightAnchor, multiplier: M).isActive = true

constraint(greaterThanOrEqualTo:multiplier:constant:)viewA.heightAnchor ≥≥ viewB.heightAnchor * M + C

viewA.heightAnchor.constraint(greaterThanOrEqualTo: viewB.heightAnchor, multiplier: M, constant: C).isActive = true

constraint(greaterThanOrEqualToConstant:)viewA.heightAnchor ≥≥ C

viewA.heightAnchor.constraint(greaterThanOrEqualToConstant: C).isActive = true

constraint(lessThanOrEqualTo:multiplier:)viewA.heightAnchor ≤≤ viewB.heightAnchor * M

viewA.heightAnchor.constraint(lessThanOrEqualTo: viewB.heightAnchor, multiplier: M).isActive = true

constraint(lessThanOrEqualTo:multiplier:constant:)viewA.heightAnchor ≤≤ viewB.heightAnchor * M + C

viewA.heightAnchor.constraint(lessThanOrEqualTo: viewB.heightAnchor, multiplier: M, constant: C).isActive = true

constraint(lessThanOrEqualToConstant:)viewA.heightAnchor ≤≤ C

viewA.heightAnchor.constraint(lessThanOrEqualToConstant: C).isActive = true


SuperLayout is available under the Apache 2.0 license. See LICENSE for more info.