Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lionheart/SuperLayout

SuperLayout is a Swift library that makes using Auto Layout a breeze.
https://github.com/lionheart/SuperLayout

apache2 auto-layout ios swift swift-library swift4

Last synced: 3 months ago
JSON representation

SuperLayout is a Swift library that makes using Auto Layout a breeze.

Awesome Lists containing this project

README

        

![](meta/repo-banner.png)
[![](meta/repo-banner-bottom.png)][lionheart-url]

[![CI Status](http://img.shields.io/travis/lionheart/SuperLayout.svg?style=flat)](https://travis-ci.org/lionheart/SuperLayout)
[![Version](https://img.shields.io/cocoapods/v/SuperLayout.svg?style=flat)](http://cocoapods.org/pods/SuperLayout)
[![License](https://img.shields.io/cocoapods/l/SuperLayout.svg?style=flat)](http://cocoapods.org/pods/SuperLayout)
[![Platform](https://img.shields.io/cocoapods/p/SuperLayout.svg?style=flat)](http://cocoapods.org/pods/SuperLayout)

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.

## 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](https://developer.apple.com/reference/uikit/nslayoutanchor). 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:)](https://developer.apple.com/reference/uikit/nslayoutanchor/1500946-constraint) ➥ `viewA.rightAnchor ~~ viewB.leftAnchor`

Original

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

[constraint(equalTo:constant:)](https://developer.apple.com/reference/uikit/nslayoutanchor/1500937-constraint) ➥ `viewA.rightAnchor ~~ viewB.leftAnchor + C`

Original

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

[constraint(greaterThanOrEqualTo:)](https://developer.apple.com/reference/uikit/nslayoutanchor/1500936-constraint) ➥ `viewA.rightAnchor ≥≥ viewB.leftAnchor`

Original

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

[constraint(greaterThanOrEqualTo:constant:)](https://developer.apple.com/reference/uikit/nslayoutanchor/1500948-constraint) ➥ `viewA.rightAnchor ≥≥ viewB.leftAnchor + C`

Original

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

[constraint(lessThanOrEqualTo:)](https://developer.apple.com/reference/uikit/nslayoutanchor/1500953-constraint) ➥ `viewA.rightAnchor ≤≤ viewB.leftAnchor`

Original

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

[constraint(lessThanOrEqualTo:constant:)](https://developer.apple.com/reference/uikit/nslayoutanchor/1500959-constraint) ➥ `viewA.rightAnchor ≤≤ viewB.leftAnchor + C`

Original

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

---

## NSLayoutDimension Reference

[constraint(equalTo:multiplier:)](https://developer.apple.com/reference/uikit/nslayoutdimension/1500951-constraint) ➥ `viewA.heightAnchor ~~ viewB.heightAnchor * M`

Original

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

[constraint(equalTo:multiplier:constant:)](https://developer.apple.com/reference/uikit/nslayoutdimension/1500934-constraint) ➥ `viewA.heightAnchor ~~ viewB.heightAnchor * M + C`

Original

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

[constraint(equalToConstant:)](https://developer.apple.com/reference/uikit/nslayoutdimension/1500941-constraint) ➥ `viewA.heightAnchor ~~ C`

Original

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

[constraint(greaterThanOrEqualTo:multiplier:)](https://developer.apple.com/reference/uikit/nslayoutdimension/1500961-constraint) ➥ `viewA.heightAnchor ≥≥ viewB.heightAnchor * M`

Original

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

[constraint(greaterThanOrEqualTo:multiplier:constant:)](https://developer.apple.com/reference/uikit/nslayoutdimension/1500965-constraint) ➥ `viewA.heightAnchor ≥≥ viewB.heightAnchor * M + C`

Original

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

[constraint(greaterThanOrEqualToConstant:)](https://developer.apple.com/reference/uikit/nslayoutdimension/1500939-constraint) ➥ `viewA.heightAnchor ≥≥ C`

Original

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

[constraint(lessThanOrEqualTo:multiplier:)](https://developer.apple.com/reference/uikit/nslayoutdimension/1500943-constraint) ➥ `viewA.heightAnchor ≤≤ viewB.heightAnchor * M`

Original

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

[constraint(lessThanOrEqualTo:multiplier:constant:)](https://developer.apple.com/reference/uikit/nslayoutdimension/1500957-constraint) ➥ `viewA.heightAnchor ≤≤ viewB.heightAnchor * M + C`

Original

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

[constraint(lessThanOrEqualToConstant:)](https://developer.apple.com/reference/uikit/nslayoutdimension/1500963-constraint) ➥ `viewA.heightAnchor ≤≤ C`

Original

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

## License

SuperLayout is available under the Apache 2.0 license. See [LICENSE](LICENSE) for more info.

[lionheart-url]: https://lionheartsw.com/