Home

Awesome

EasySwiftLayout

Platform Cocoapods Compatible Carthage compatible

I am glad to share with you a lightweight Swift framework for Apple's Auto-Layout. It helps you write readable and compact UI code using simple API.

At first, it was only a few extenstions of UIView desiged for some of my commercial projects, but eventually code continued to grow, so I decided to move it to a seperate framework. I hope some of you find it helpful, so feel free to share your feedback and give some stars to EasySwiftLayout!

If you want to report bug or request new feature - open a ticket. I will try my best to cover them as soon as posible.

Contents

Requirements

Documentation

All methods in EasySwiftLayout designed to be self-explaining, but at the same time all of them includes detail description of usage. You can check it both in code by pressing key and clicking on the method, and in our API Cheat Sheet section down below.

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate EasySwiftLayout into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'EasySwiftLayout'

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate EasySwiftLayout into your Xcode project using Carthage, specify it in your Cartfile:

github "denandreychuk/EasySwiftLayout"

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler. It is in early development, but EasySwiftLayout does support its use on supported platforms.

Once you have your Swift package set up, adding EasySwiftLayout as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/Pimine/EasySwiftLayout.git", .upToNextMajor(from: "1.6.0"))
]

Manually

If you prefer not to use any of the aforementioned dependency managers, you can integrate EasySwiftLayout into your project manually.

Embedded Framework

Usage

Quick Start

import EasySwiftLayout

class ViewController: UIViewController {
    private let boxView = UIView()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        addAndLayoutSubviews()
    }
    
    private func addAndLayoutSubviews() {        
        boxView
            .add(toSuperview: view)
            .centerInSuperview()
            .size(toSquareWithSide: 50)
    }
}

Example

<img src="https://github.com/denandreychuk/EasySwiftLayout/blob/master/Resources/Example.jpg?raw=true" width="200">

EasySwiftLayout comes with project example. You can check out how easily you can create screens like this with ESL:

API Cheat Sheet

UIView Extenstions:

Helpers

<details> <summary><code>add(toSuperview:)</code></summary>
Summary

Adds the view as a subview of specified superview.

Declaration
func add(toSuperview superview: UIView) -> Self
Parameters
ParameterTypeDescription
superviewUIViewThe superview to which add subview.
Returns

self with attribute @discardableResult.

Declared In

UIView + Helpers.swift

</details>

Size Methods (Constants)

<details> <summary><code>width(_:usingRelation:priority:)</code></summary>
Summary

Sets the width of the view using the specified type of relation to the given size with the priority of the constraint.

Declaration
func width(_ width: CGFloat, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion
Precondition

Pass size greater than zero, otherwise this method will have no effect.

Parameters
ParameterTypeDescription
widthCGFloatThe value to set this view width to.
relationNSLayoutConstraint.RelationThe type of relationship for constraint.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Size.swift

</details> <details> <summary><code>height(_:usingRelation:priority:)</code></summary>
Summary

Sets the height of the view using the specified type of relation to the given size with the priority of the constraint.

Declaration
func height(_ height: CGFloat, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion
Precondition

Pass size greater than zero, otherwise this method will have no effect.

Parameters
ParameterTypeDescription
heightCGFloatThe value to set this view height to.
relationNSLayoutConstraint.RelationThe type of relationship for constraint.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Size.swift

</details> <details> <summary><code>size(_:usingRelation:priority:)</code></summary>
Summary

Sets the dimensions of the view using the specified type of relation to the given size with the priority of the constraint.

Declaration
func size(_ size: CGSize, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion
Precondition

Pass size greater than zero, otherwise this method will have no effect.

Parameters
ParameterTypeDescription
sizeCGSizeThe size to set this view dimensions to.
relationNSLayoutConstraint.RelationThe type of relationship for constraint.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Size.swift

</details> <details> <summary><code>size(toSquareWithSide:usingRelation:priority:)</code></summary>
Summary

Sets the dimensions of the view to a square with the side using the specified type of relation to the given size with the priority of the constraint.

Declaration
func size(toSquareWithSide side: CGFloat, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion
Precondition

Pass side greater than zero, otherwise this method will have no effect.

Parameters
ParameterTypeDescription
sideCGFloatSquare side to set this view dimensions to.
relationNSLayoutConstraint.RelationThe type of relationship for constraint.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Size.swift

</details>

Size Methods (Another view)

<details> <summary><code>width(match:withInset:usingRelation:priority:)</code></summary>
Summary

Sets the width of the view using the specified type of relation to the width of another view with the inset and priority of the constraint.

Declaration
func width(match anotherView: UIView, withInset inset: CGFloat = .zero, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion
Parameters
ParameterTypeDescription
anotherViewUIViewAnother view to set this view width to.
insetCGFloatThe value to inset (or shrunk) the width. Negative value cause the width to be outset (or expanded).
relationNSLayoutConstraint.RelationThe type of relationship for constraint.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Size.swift

</details> <details> <summary><code>height(match:withInset:usingRelation:priority:)</code></summary>
Summary

Sets the height of the view using the specified type of relation to the height of another view with the inset and priority of the constraint.

Declaration
func height(match anotherView: UIView, withInset inset: CGFloat = .zero, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion
Parameters
ParameterTypeDescription
anotherViewUIViewAnother view to set this view height to.
insetCGFloatThe value to inset (or shrunk) the height. Negative value cause the height to be outset (or expanded).
relationNSLayoutConstraint.RelationThe type of relationship for constraint.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Size.swift

</details> <details> <summary><code>size(match:withInsets:usingRelation:priority:)</code></summary>
Summary

Sets the size of the view using the specified type of relation to the size of another view with the insets and priority of the constraints.

Declaration
func size(match anotherView: UIView, withInsets insets: ESLSizeInsets = .zero, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion
Parameters
ParameterTypeDescription
anotherViewUIViewAnother view to set this view height to.
insetsESLSizeInsetsThe values to inset (or shrunk) the size. Negative values cause the size to be outset (or expanded).
relationNSLayoutConstraint.RelationThe type of relationship for constraint.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Size.swift

</details> <details> <summary><code>size(match:withInset:usingRelation:priority:)</code></summary>
Summary

Sets the size of the view using the specified type of relation to the size of another view with the insets and priority of the constraints.

Declaration
func size(match anotherView: UIView, withInset inset: CGFloat, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion
Parameters
ParameterTypeDescription
anotherViewUIViewAnother view to set this view height to.
insetCGFloatThe value to inset (or shrunk) the size. Negative value cause the size to be outset (or expanded).
relationNSLayoutConstraint.RelationThe type of relationship for constraint.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Size.swift

</details>

Pin Methods

<details> <summary><code>pin(topTo:leftTo:bottomTo:rightTo:withInsets:priority:)</code></summary>
Summary

Pins the edges to the given NSLayoutAxisAnchors with the insets and priority of the constraints.

Declaration
func pin(topTo top: NSLayoutYAxisAnchor? = nil, leftTo left: NSLayoutXAxisAnchor? = nil, bottomTo bottom: NSLayoutYAxisAnchor? = nil, rightTo right: NSLayoutXAxisAnchor? = nil, withInsets insets: UIEdgeInsets = .zero, priority: UILayoutPriority = .required) -> Self
Discussion
Precondition

You should pass at least one anchor, otherwise this method will have no effect.

Parameters
ParameterTypeDescription
topNSLayoutYAxisAnchorThe anchor to pin top to.
leftNSLayoutXAxisAnchorThe anchor to pin left to.
bottomNSLayoutYAxisAnchorThe anchor to pin bottom to.
rightNSLayoutXAxisAnchorThe anchor to pin right to.
insetsUIEdgeInsetsThe insets between the edges.
priorityUILayoutPriorityThe priority of the constraints.
Returns

self with attribute @discardableResult.

Declared In

UIView + Pin.swift

</details> <details> <summary><code>pinEdge(_:toEdge:ofView:withInset:usingRelation:priority:)</code></summary>
Summary

Pins the edge of the view using the specified type of relation to the given edge of another view with the inset and priority of the constraint.

Declaration
func pinEdge(_ edge: ESLEdge, toEdge pinningEdge: ESLEdge, ofView anotherView: UIView, withInset inset: CGFloat = .zero, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion
Precondition
Parameters
ParameterTypeDescription
edgeESLEdgeThe edge of this view to pin.
pinningEdgeESLEdgeThe edge of another view to pin to.
anotherViewNSLayoutYAxisAnchorAnother view to pin to.
insetCGFloatThe inset between the edge of this view and the edge of another view.
relationNSLayoutConstraint.RelationThe type of relationship for the constraint.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Pin.swift

</details> <details> <summary><code>pinEdge(_:toSameEdgeOfView:withInset:usingRelation:priority:)</code></summary>
Summary

Pins the given edge of the view using the specified type of relation to the corresponding margin of another view with the inset and priority of the constraint.

Declaration
func pinEdge(_ edge: ESLEdge, toSameEdgeOfView anotherView: UIView, withInset inset: CGFloat = .zero, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion

To make Auto-Layout works properly, it automatically sets view’s property translatesAutoresizingMaskIntoConstraints to false.

Precondition

Another view must be in the same view hierarchy as this view.

Parameters
ParameterTypeDescription
edgeESLEdgeThe edge of this view to pin.
anotherViewNSLayoutYAxisAnchorAnother view to pin to.
insetCGFloatThe inset beetween the edge of this view and the corresponding edge of another view.
relationNSLayoutConstraint.RelationThe type of relationship for the constraint.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Pin.swift

</details> <details> <summary><code>pinEdges(_:toSameEdgesOfView:withInsets:usingRelation:priority:)</code></summary>
Summary

Pins the given edges of the view using the specified type of relation to the corresponding margins of another view with the insets and priority of the constraints.

Declaration
func pinEdges(_ edges: [ESLEdge] = ESLEdge.all, toSameEdgesOfView anotherView: UIView, withInsets insets: UIEdgeInsets = .zero, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion
Precondition

Another view must be in the same view hierarchy as this view.

Parameters
ParameterTypeDescription
edges[ESLEdge]The edges of this view to pin.
anotherViewNSLayoutYAxisAnchorAnother view to pin to.
insetsUIEdgeInsetsThe insets beetween the edges of this view and corresponding edges of another view.
relationNSLayoutConstraint.RelationThe type of relationship for the constraints.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Pin.swift

</details> <details> <summary><code>pinEdges(_:toSameEdgesOfView:withInset:usingRelation:priority:)</code></summary>
Summary

Pins the given edges of the view using the specified type of relation to the corresponding margins of another view with the equal insets and priority of the constraints.

Declaration
func pinEdges(_ edges: [ESLEdge] = ESLEdge.all, toSameEdgesOfView anotherView: UIView, withInset inset: CGFloat, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion
Precondition

Another view must be in the same view hierarchy as this view.

Parameters
ParameterTypeDescription
edges[ESLEdge]The edges of this view to pin.
anotherViewNSLayoutYAxisAnchorAnother view to pin to.
insetsCGFloatThe inset beetween the edges of this view and corresponding edges of another view.
relationNSLayoutConstraint.RelationThe type of relationship for the constraints.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Pin.swift

</details> <details> <summary><code>pinEdges(ofGroup:toSameEdgesOfView:withInset:usingRelation:priority:)</code></summary>
Summary

Pins edges of the view of the given group using the specified type of relation to the corresponding margins of another view with the equal insets and priority of the constraints.

Declaration
func pinEdges(ofGroup edgeGroup: ESLEdgeGroup, toSameEdgesOfView anotherView: UIView, withInset inset: CGFloat, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion

To make Auto-Layout works properly, it automatically sets view property translatesAutoresizingMaskIntoConstraints to false.

Precondition

Another view must be in the same view hierarchy as this view.

Parameters
ParameterTypeDescription
edgeGroupESLEdgeGroupThe group of edges of this view to pin to.
anotherViewNSLayoutYAxisAnchorAnother view to pin to.
insetsCGFloatThe inset beetween the edges of this view and corresponding edges of another view.
relationNSLayoutConstraint.RelationThe type of relationship for the constraints.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Pin.swift

</details> <details> <summary><code>pinEdges(toSameEdgesOfView:excludingEdge:withInsets:usingRelation:priority:)</code></summary>
Summary

Pins the edges of the view using the specified type of relation to the corresponding margins of another view with the insets and priority of the constraints, excluding one edge

Declaration
func pinEdges(toSameEdgesOfView anotherView: UIView, excludingEdge excludedEdge: ESLEdge, withInsets insets: UIEdgeInsets = .zero, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion
Precondition

Another view must be in the same view hierarchy as this view.

Parameters
ParameterTypeDescription
anotherViewNSLayoutYAxisAnchorAnother view to pin to.
excludedEdgeESLEdgeThe edge to be ingored and not pinned.
insetsUIEdgeInsetsThe insets beetween the edges of this view and corresponding edges of another view.
relationNSLayoutConstraint.RelationThe type of relationship for the constraints.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Pin.swift

</details> <details> <summary><code>pinEdges(toSameEdgesOfView:excludingEdge:withInset:usingRelation:priority:)</code></summary>
Summary

Pins the edges of the view using the specified type of relation to the corresponding margins of another view with the equal inset and priority of the constraints, excluding one edge.

Declaration
func pinEdges(toSameEdgesOfView anotherView: UIView, excludingEdge excludedEdge: ESLEdge, withInset inset: CGFloat, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion
Precondition

Another view must be in the same view hierarchy as this view.

Parameters
ParameterTypeDescription
anotherViewNSLayoutYAxisAnchorAnother view to pin to.
excludedEdgeESLEdgeThe edge to be ingored and not pinned.
insetCGFloatThe inset beetween the edges of this view and corresponding edges of another view.
relationNSLayoutConstraint.RelationThe type of relationship for the constraints.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Pin.swift

</details> <details> <summary><code>pinEdge(_:toEdge:ofGuide:withInset:usingRelation:priority:)</code></summary>
Summary

Pins the edge of the view using the specified type of relation to the given edge of guide with the inset and priority of the constraint.

Declaration
func pinEdge(_ edge: ESLEdge, toEdge pinningEdge: ESLEdge, ofGuide guide: ESLGuide, withInset inset: CGFloat = .zero, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion
Precondition

Pin edges with same axis or method will throw fatal error.

Parameters
ParameterTypeDescription
edgeESLEdgeThe edge of this view to pin.
pinningEdgeESLEdgeThe edge of another view to pin to.
guideESLGuideThe guide to pin to..
insetCGFloatThe inset between the edge of this view and the edge of another view.
relationNSLayoutConstraint.RelationThe type of relationship for the constraint.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Pin.swift

</details> <details> <summary><code>pinEdge(_:toSameEdgeOfGuide:withInset:usingRelation:priority:)</code></summary>
Summary

Pins the given edge of the view using the specified type of relation to the corresponding margin of guide with the inset and priority of the constraint.

Declaration
func pinEdge(_ edge: ESLEdge, toSameEdgeOfGuide guide: ESLGuide, withInset inset: CGFloat = .zero, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion

To make Auto-Layout works properly, it automatically sets view’s property translatesAutoresizingMaskIntoConstraints to false.

Parameters
ParameterTypeDescription
edgeESLEdgeThe edge of this view to pin.
guideESLGuideThe guide to pin to.
insetCGFloatThe inset beetween the edge of this view and the corresponding edge of another view.
relationNSLayoutConstraint.RelationThe type of relationship for the constraint.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Pin.swift

</details> <details> <summary><code>pinEdges(_:toSameEdgesOfGuide:withInsets:usingRelation:priority:)</code></summary>
Summary

Pins the given edges of the view using the specified type of relation to the corresponding margins of guide with the insets and priority of the constraints.

Declaration
func pinEdges(_ edges: [ESLEdge] = ESLEdge.all, toSameEdgesOfGuide guide: ESLGuide, withInsets insets: UIEdgeInsets = .zero, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion
Parameters
ParameterTypeDescription
edges[ESLEdge]The edges of this view to pin.
guideESLGuideThe guide to pin to..
insetsUIEdgeInsetsThe insets beetween the edges of this view and corresponding edges of another view.
relationNSLayoutConstraint.RelationThe type of relationship for the constraints.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Pin.swift

</details> <details> <summary><code>pinEdges(_:toSameEdgesOfGuide:withInset:usingRelation:priority:)</code></summary>
Summary

Pins the given edges of the view using the specified type of relation to the corresponding margins of guide with the equal insets and priority of the constraints.

Declaration
func pinEdges(_ edges: [ESLEdge] = ESLEdge.all, toSameEdgesOfGuide guide: ESLGuide, withInset inset: CGFloat, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion
Parameters
ParameterTypeDescription
edges[ESLEdge]The edges of this view to pin.
guideESLGuideThe guide to pin to.
insetsCGFloatThe inset beetween the edges of this view and corresponding edges of another view.
relationNSLayoutConstraint.RelationThe type of relationship for the constraints.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Pin.swift

</details> <details> <summary><code>pinEdges(ofGroup:toSameEdgesOfGuide:withInset:usingRelation:priority:)</code></summary>
Summary

Pins edges of the view of the given group using the specified type of relation to the corresponding margins of guide with the equal insets and priority of the constraints.

Declaration
func pinEdges(ofGroup edgeGroup: ESLEdgeGroup, toSameEdgesOfGuide guide: ESLGuide, withInset inset: CGFloat, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion

To make Auto-Layout works properly, it automatically sets view property translatesAutoresizingMaskIntoConstraints to false.

Parameters
ParameterTypeDescription
edgeGroupESLEdgeGroupThe group of edges of this view to pin to.
guideESLGuideThe guide to pin to.
insetsCGFloatThe inset beetween the edges of this view and corresponding edges of another view.
relationNSLayoutConstraint.RelationThe type of relationship for the constraints.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Pin.swift

</details> <details> <summary><code>pinEdges(toSameEdgesOfGuide:excludingEdge:withInsets:usingRelation:priority:)</code></summary>
Summary

Pins the edges of the view using the specified type of relation to the corresponding margins of guide with the insets and priority of the constraints, excluding one edge.

Declaration
func pinEdges(toSameEdgesOfGuide guide: ESLGuide, excludingEdge excludedEdge: ESLEdge, withInsets insets: UIEdgeInsets = .zero, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion
Parameters
ParameterTypeDescription
guideESLGuideThe guide to pin to.
excludedEdgeESLEdgeThe edge to be ingored and not pinned.
insetsUIEdgeInsetsThe insets beetween the edges of this view and corresponding edges of another view.
relationNSLayoutConstraint.RelationThe type of relationship for the constraints.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Pin.swift

</details> <details> <summary><code>pinEdges(toSameEdgesOfGuide:excludingEdge:withInset:usingRelation:priority:)</code></summary>
Summary

Pins the edges of the view using the specified type of relation to the corresponding margins of guide with the equal inset and priority of the constraints, excluding one edge.

Declaration
func pinEdges(toSameEdgesOfGuide guide: ESLGuide, excludingEdge excludedEdge: ESLEdge, withInset inset: CGFloat, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion
Parameters
ParameterTypeDescription
guideESLGuideThe guide to pin to.
excludedEdgeESLEdgeThe edge to be ingored and not pinned.
insetCGFloatThe inset beetween the edges of this view and corresponding edges of guide.
relationNSLayoutConstraint.RelationThe type of relationship for the constraints.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Pin.swift

</details>

Pin to Superview Methods

Just to remind, let's say you have a view called MyView, which has a UIButton(loginButton) over it. In this case, MyView is a superview for loginButton and loginButton is a subview of MyView.

<details> <summary><code>pinEdge(_:toSuperviewEdge:withInset:respectingGuide:usingRelation:priority:)</code></summary>
Summary

Pins the edge of the view using the specified type of relation to the given edge of its superview with the inset and priority of the constraint. Optionally respects one of pre-defined Apple's layout guides.

Declaration
func pinEdge(_ edge: ESLEdge, toSuperviewEdge superviewEdge: ESLEdge, withInset inset: CGFloat = .zero, respectingGuide guide: ESLSuperviewGuide = .none, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion
Precondition
Parameters
ParameterTypeDescription
edgeESLEdgeThe edge of this view to pin.
superviewEdgeESLEdgeThe edge of its superview to pin to.
insetCGFloatThe inset between the edge of this view and the edge of its superview.
guideESLSuperviewGuideThe guide to respect in layout.
relationNSLayoutConstraint.RelationThe type of relationship for constraint.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Pin(Superview).swift

</details> <details> <summary><code>pinEdgeToSuperview(_:withInset:respectingGuide:usingRelation:priority:)</code></summary>
Summary

Pins the given edge of the view using the specified type of relation to the corresponding margin of its superview with the inset and priority of the constraint. Optionally respects one of pre-defined Apple's layout guides.

Declaration
func pinEdgeToSuperview(_ edge: ESLEdge, withInset inset: CGFloat = .zero, respectingGuide guide: ESLSuperviewGuide = .none, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion

To make Auto-Layout works properly, it automatically sets view property translatesAutoresizingMaskIntoConstraints to false.

Precondition

The view should have the superview, otherwise this method will have no effect.

Parameters
ParameterTypeDescription
edgeESLEdgeThe edge of this view to pin.
insetCGFloatThe inset beetween the edge of this view and the corresponding edge of its superview.
guideESLSuperviewGuideThe guide to respect in layout.
relationNSLayoutConstraint.RelationThe type of relationship for constraint.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Pin(Superview).swift

</details> <details> <summary><code>pinEdgesToSuperview(_:withInsets:respectingGuide:usingRelation:priority:)</code></summary>
Summary

Pins the given edges of the view using the specified type of relation to the corresponding margins of its superview with the insets and priority of the constraints. Optionally respects one of pre-defined Apple's layout guides.

Declaration
func pinEdgesToSuperview(_ edges: [ESLEdge] = ESLEdge.all, withInsets insets: UIEdgeInsets = .zero, respectingGuide guide: ESLSuperviewGuide = .none, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion
  1. If you don't need to customize the insets based on the edge, use pinEdgesToSuperview(_:withInset:usingRelation:priority:).

  2. To make Auto-Layout works properly, it automatically sets view property translatesAutoresizingMaskIntoConstraints to false.

Precondition

The view should have the superview, otherwise this method will have no effect.

Parameters
ParameterTypeDescription
edges[ESLEdge]The edges of this view to pin.
insetsUIEdgeInsetsThe insets beetween the edges of this view and the corresponding edges of its superview.
guideESLSuperviewGuideThe guide to respect in layout.
relationNSLayoutConstraint.RelationThe type of relationship for constraint.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Pin(Superview).swift

</details> <details> <summary><code>pinEdgesToSuperview(_:withInset:respectingGuide:usingRelation:priority:)</code></summary>
Summary

Pins the given edges of the view using the specified type of relation to the corresponding margins of its superview with the equal insets and priority of the constraints. Optionally respects one of pre-defined Apple's layout guides.

Declaration
func pinEdgesToSuperview(_ edges: [ESLEdge] = ESLEdge.all, withInset inset: CGFloat, respectingGuide guide: ESLSuperviewGuide = .none, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion
  1. If you need to customize the insets based on the edge, use pinEdgesToSuperview(_:withInsets:usingRelation:priority:).

  2. To make Auto-Layout works properly, it automatically sets view property translatesAutoresizingMaskIntoConstraints to false

Precondition

The view should have the superview, otherwise this method will have no effect.

Parameters
ParameterTypeDescription
edges[ESLEdge]The edges of this view to pin.
insetCGFloatThe inset beetween the edges of this view and the orresponding edges of its superview.
guideESLSuperviewGuideThe guide to respect in layout.
relationNSLayoutConstraint.RelationThe type of relationship for constraint.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Pin(Superview).swift

</details> <details> <summary><code>pinEdgesToSuperview(ofGroup:withInset:respectingGuide:usingRelation:priority:)</code></summary>
Summary

Pins edges of the view of the given group using the specified type of relation to the corresponding margins of its superview with the equal insets and priority of the constraints. Optionally respects one of pre-defined Apple's layout guides.

Declaration
func pinEdgesToSuperview(ofGroup group: ESLEdgeGroup, withInset inset: CGFloat = .zero, respectingGuide guide: ESLSuperviewGuide = .none, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion

To make Auto-Layout works properly, it automatically sets view property translatesAutoresizingMaskIntoConstraints to false

Precondition

The view should have the superview, otherwise this method will have no effect.

Parameters
ParameterTypeDescription
groupESLEdgeGroupThe group of edges of this view to pin to.
insetCGFloatThe inset beetween the edges of this view and the orresponding edges of its superview.
guideESLSuperviewGuideThe guide to respect in layout.
relationNSLayoutConstraint.RelationThe type of relationship for constraint.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Pin(Superview).swift

</details> <details> <summary><code>pinEdgesToSuperview(excludingEdge:withInsets:respectingGuide:usingRelation:priority:)</code></summary>
Summary

Pins the edges of the view using the specified type of relation to the corresponding margins of its superview with the insets and priority of the constraints, excluding one edge. Optionally respects one of pre-defined Apple's layout guides.

Declaration
func pinEdgesToSuperview(excludingEdge excludedEdge: ESLEdge, withInsets insets: UIEdgeInsets = .zero, respectingGuide guide: ESLSuperviewGuide = .none, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion
  1. If you don't need to customize the insets based on the edge, use pinEdgesToSuperview(excludingEdge:withInset:usingRelation:priority:).

  2. To make Auto-Layout works properly, it automatically sets view property translatesAutoresizingMaskIntoConstraints to false.

Precondition

The view should have the superview, otherwise this method will have no effect.

Parameters
ParameterTypeDescription
excludedEdgeESLEdgeThe edge to be ingored and not pinned.
insetsUIEdgeInsetsThe insets beetween the edges of this view and the orresponding edges of its superview.
guideESLSuperviewGuideThe guide to respect in layout.
relationNSLayoutConstraint.RelationThe type of relationship for constraint.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Pin(Superview).swift

</details> <details> <summary><code>pinEdgesToSuperview(excludingEdge:withInset:respectingGuide:usingRelation:priority:)</code></summary>
Summary

Pins the edges of the view using the specified type of relation to the corresponding margins of its superview with the equal inset and priority of the constraints, excluding one edge. Optionally respects one of pre-defined Apple's layout guides.

Declaration
func pinEdgesToSuperview(excludingEdge excludedEdge: ESLEdge, withInset inset: CGFloat, respectingGuide guide: ESLSuperviewGuide = .none, usingRelation relation: NSLayoutConstraint.Relation = .equal, priority: UILayoutPriority = .required) -> Self
Discussion
  1. If you need to customize the insets based on the edge, use pinEdgesToSuperview(excludingEdge:withInset:usingRelation:priority:).

  2. To make Auto-Layout works properly, it automatically sets view property translatesAutoresizingMaskIntoConstraints to false.

Precondition

The view should have the superview, otherwise this method will have no effect.

Parameters
ParameterTypeDescription
excludedEdgeESLEdgeThe edge to be ingored and not pinned.
insetCGFloatThe inset beetween the edges of this view and the orresponding edges of its superview.
guideESLSuperviewGuideThe guide to respect in layout.
relationNSLayoutConstraint.RelationThe type of relationship for constraint.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Pin(Superview).swift

</details>

Center Methods

<details> <summary><code>centerInView(_:withOffset:priority:)</code></summary>
Summary

Centers the view in another view with the offset and priority of the constraint.

Declaration
func centerInView(_ anotherView: UIView, withOffset offset: UIOffset = .zero, priority: UILayoutPriority = .required) -> Self
Discussion

To make Auto-Layout works properly, it automatically sets view property translatesAutoresizingMaskIntoConstraints to false

Precondition

Another view must be in the same view hierarchy as this view.

Parameters
ParameterTypeDescription
anotherViewUIViewAnother view to center in.
offsetUIOffsetAxis offset.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Center.swift

</details> <details> <summary><code>centerInView(_:axis:withOffset:priority:)</code></summary>
Summary

Centers the axis of this view in another view with the offset and priority of the constraint.

Declaration
func centerInView(_ anotherView: UIView, axis: ESLAxis, withOffset offset: CGFloat = .zero, priority: UILayoutPriority = .required) -> Self
Discussion

To make Auto-Layout works properly, it automatically sets view property translatesAutoresizingMaskIntoConstraints to false

Precondition

Another view must be in the same view hierarchy as this view.

Parameters
ParameterTypeDescription
anotherViewUIViewView to center in.
axisESLAxisAxis to center
offsetUIOffsetAxis offset.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Center.swift

</details> <details> <summary><code>centerInSuperview(withOffset:priority:)</code></summary>
Summary

Centers the view in its superview view with the offset and priority of the constraint.

Declaration
func centerInSuperview(withOffset offset: UIOffset = .zero, priority: UILayoutPriority = .required) -> Self
Discussion

To make Auto-Layout works properly, it automatically sets view property translatesAutoresizingMaskIntoConstraints to false

Precondition

The view should have the superview, otherwise this method will have no effect.

Parameters
ParameterTypeDescription
offsetUIOffsetAxis offset.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Center.swift

</details> <details> <summary><code>centerInSuperview(axis:withOffset:priority:)</code></summary>
Summary

Centers the axis of this view in its superview with the offset and priority of the constraint.

Declaration
func centerInSuperview(axis: ESLAxis, withOffset offset: CGFloat = .zero, priority: UILayoutPriority = .required) -> Self
Discussion

To make Auto-Layout works properly, it automatically sets view property translatesAutoresizingMaskIntoConstraints to false

Precondition

The view should have the superview, otherwise this method will have no effect.

Parameters
ParameterTypeDescription
axisESLAxisAxis to center.
offset`CGFloatAxis offset.
priorityUILayoutPriorityThe priority of the constraint.
Returns

self with attribute @discardableResult.

Declared In

UIView + Center.swift

</details>

License

EasySwiftLayout is released under the MIT license. See LICENSE for details.