Latest 1.0.3
Homepage https://github.com/adamdebono/SwiftConstraints
License MIT
Platforms ios 8.0, tvos 9.0
Frameworks UIKit
Authors

Swifty mappings for NSLayoutConstraint.

Installation

Cocoapods

pod 'SwiftConstraints', '~> 1.0.1'

Usage

Add a constraint between a view’s subview

// align the subview 10 points from the left of the superview
superview.addConstraint(toItem: subview, attribute: .leading, constant: 10)

// align the subview 20 points or less from the vertical center of the superview
superview.addConstraint(toItem: subview, attribute: .centerY, relatedBy: .lessThanOrEqual, constant: 20)

Add constraints to fill a view

// subview completely fill the superview
superview.addConstraints(fillView: subview)

// subview fill the superview with 20 points of padding
superview.addConstraints(fillView: subview, constant: 20)

Add constraints to two of the view’s subviews

// align the left sides of two view by 10 points
superview.addConstraint(withItems: viewOne, andItem: viewTwo, attribute: .left, constant: 10)

// align the first baseline of two labels
superview.addConstraint(withItems: labelOne, andItem: labelTwo, attribute: .firstBaseline)

Add constraints between two of the view’s subviews

// sit two views next to each other horizontally
superview.addConstraint(betweenItems: viewOne, toItem: viewTwo, axis: .horizontal)

// put the second view underneath the first view by 15 points
superview.addConstraint(betweenItems: viewOne, toItem: viewTwo, axis: .vertical, constant: 15)

Add a constraint to the view itself

// set the view width to 120 points
superview.addConstraint(toSelf: .width, constant: 120)

// set the aspect ratio of the view to 16:9 or greater
superview.addConstraint(toSelf: .width, toAttribute: .height, multiplier: 16/9.0, constant: 0)

Add constraints to give equal dimensions to subviews

// Set views to the same height
superview.addConstraints(equalDimensions: [viewOne, viewTwo, viewThreee, viewFour], axis: .vertical)

Add constraints to align subviews

// Align views to the horizontal center of the view
superview.addConstraints(alignItems: [viewOne, viewTwo, viewThreee, viewFour], attribute: .centerX)

Add constraints to space subviews

// evenly space views horizontally with 20 points of padding in a superview
superview.addConstraints(equallySpaced: [viewOne, viewTwo, viewThreee, viewFour], axis: .horizontal, constant: 20)

Latest podspec

{
    "name": "SwiftConstraints",
    "version": "1.0.3",
    "summary": "Simple shortcuts for AutoLayout",
    "homepage": "https://github.com/adamdebono/SwiftConstraints",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Adam Debono": "[email protected]"
    },
    "platforms": {
        "ios": "8.0",
        "tvos": "9.0"
    },
    "source": {
        "git": "https://github.com/adamdebono/SwiftConstraints.git",
        "tag": "1.0.3"
    },
    "source_files": "Source/SwiftConstraints.swift",
    "frameworks": "UIKit",
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This