Latest 2.0.0
Homepage https://github.com/lionheart/SuperLayout
License Apache 2.0
Platforms ios 9.3, requires ARC
Authors

SuperLayout
SuperLayout

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:

SuperLayout

Into this:

SuperLayout

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.

Installation

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

Original

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

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

Original

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

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

Original

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

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

Original

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

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

Original

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

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

Original

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


NSLayoutDimension Reference

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

Original

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

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

Original

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

constraint(equalToConstant:)viewA.heightAnchor ~~ C

Original

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

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

Original

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

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

Original

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

constraint(greaterThanOrEqualToConstant:)viewA.heightAnchor ≥≥ C

Original

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

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

Original

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

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

Original

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

constraint(lessThanOrEqualToConstant:)viewA.heightAnchor ≤≤ C

Original

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

License

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

Latest podspec

{
    "name": "SuperLayout",
    "version": "2.0.0",
    "summary": "The simplest and cleanest way to use layout anchors in Swift.",
    "homepage": "https://github.com/lionheart/SuperLayout",
    "license": {
        "type": "Apache 2.0",
        "file": "LICENSE"
    },
    "authors": {
        "Dan Loewenherz": "[email protected]"
    },
    "source": {
        "git": "https://github.com/lionheart/SuperLayout.git",
        "tag": "2.0.0"
    },
    "social_media_url": "https://twitter.com/lionheartsw",
    "requires_arc": true,
    "platforms": {
        "ios": "9.3"
    },
    "swift_version": "4.2",
    "subspecs": [
        {
            "name": "Core",
            "source_files": [
                "Sources/*"
            ]
        }
    ]
}

Pin It on Pinterest

Share This