Latest 1.0.0
Homepage https://github.com/ZZYCN/LayItOut
License MIT
Platforms ios 8.0
Authors

Requirements

  • iOS 8.0+
  • Xcode 9.0+
  • Swift 4.0+

Usage

  • A sample

Creating constraints using NSLayoutConstraint

NSLayoutConstraint(item: subview,
                   attribute: .width,
                   relatedBy: .equal,
                   toItem: nil,
                   attribute: .notAnAttribute,
                   multiplier: 1.0,
                   constant: 100.0).isActive = true

NSLayoutConstraint(item: view,
                   attribute: .height,
                   relatedBy: .equal,
                   toItem: subview,
                   attribute: .height,
                   multiplier: 2.0,
                   constant: 10.0).isActive = true

Creating the same constraints using LayItOut

subview.align.width == 100.0
view.align.height == subview.align.height * 2.0 + 100.0
  • How NSLayoutAttributes represented

NSLayoutAttribute LayItOut NSLayoutAttribute LayItOut
.left view.align.left .leftMargin view.margin.left
.right view.align.right .rightMargin view.margin.right
.top view.align.top .topMargin view.margin.top
.bottom view.align.bottom .bottomMargin view.margin.bottom
.leading view.align.leading .leadingMargin view.margin.leading
.trailing view.align.trailing .trailingMargin view.margin.trailing
.width view.align.width
.height view.align.height
.centerX view.align.centerX .centerXWithinMargins view.margin.centerX
.centerY view.align.centerY .centerYWithinMargins view.margin.centerY
.lastBaseline view.align.lastBaseline
.firstBaseline view.align.firstBaseline
  • Operators representing NSLayoutRelations

Operators NSLayoutRelation
<= .lessThanOrEqual
== .equal
>= .greaterThanOrEqual

Advanced Usage

  • More operators: /, -

subview.align.height == view.align.height / 2.0 - 50.0
  • Operators in left side

subview.align.height * 2.0 + 100.0 == view.align.height
  • Use infix operator -- to prioritize

subview.align.width == 100.0 -- .defaultHigh
view.align.height == subview.align.height * 2.0 + 100.0 -- .required
  • Compositions

// Size
subview.align.size == view.align.size * 2.0 + CGSize(width: 100.0, height: 100.0)

// The same to
view.align.width == subview.align.width * 2.0 + 100.0
view.align.height == subview.align.height * 2.0 + 100.0
// Center
view.align.center == subview.align.center * 2.0 + CGPoint(x: 100.0, y: 100.0)
view.margin.center == subview.margin.center * 2.0 + CGPoint(x: 100.0, y:100.0)

// The same to
view.align.centerX == subview.align.centerX * 2.0 + 100.0
view.align.centerY == subview.align.centerY * 2.0 + 100.0
view.margin.centerX == subview.margin.centerX * 2.0 + 100.0
view.margin.centerY == subview.margin.centerY * 2.0 + 100.0
// Origin
view.align.origin == subview.align.origin * 2.0 + CGPoint(x: 100.0, y: 100.0)
view.margin.origin == subview.margin.origin * 2.0 + CGPoint(x: 100.0, y:100.0)

// The same to
view.align.leading == subview.align.leading * 2.0 + 100.0
view.align.top == subview.align.top * 2.0 + 100.0
view.margin.leading == subview.margin.leading * 2.0 + 100.0
view.margin.top == subview.margin.top * 2.0 + 100.0

Latest podspec

{
    "name": "LayItOut",
    "version": "1.0.0",
    "summary": "To create NSLayoutConstraint simply and easily.",
    "homepage": "https://github.com/ZZYCN/LayItOut",
    "license": "MIT",
    "authors": {
        "u673au667au52c7u6562": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/ZZYCN/LayItOut.git",
        "tag": "1.0.0"
    },
    "source_files": "LayItOut/*.swift",
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This