Latest0.9.2
Homepagehttps://github.com/ziligy/LucidLayout
LicenseMIT
Platformsios 10.0
Authors

Version
License
Platform

LucidLayout encapsulates Auto Layout for programmatically sizing and positioning UIViews without storyboards. It also allows for runtime variation & animation.

About

LucidLayout is a group of UIView extensions that I wrote to simplify Auto Layout. I originally wrote it thinking I would use it for quick prototyping. But I’ve realized that along with basic UIStackView, it can handle 99% of what I need to do in projects using Auto Layout.

Installation

LucidLayout is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'LucidLayout'

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Extensions Overview

Add UIView to parent

   parentView.AddSub(yourView) // use to add a single view
   parentView.AddSubviews([yourView, anotherView]) // use to add multiple views

Note: although you could use the standard addSubview you’d need to be sure and set: translatesAutoresizingMaskIntoConstraints = false LucidLayout functions do it for you

Sizing

    yourView.width(80) // set width to 80
    yourView.height(30) // set height to 30

Pinning

All pinning is relative to the inside the parent view.

    yourView.top() // pin to top of parent view
    yourView.left() // pin to parent's left-side
    yourView.bottom() // pin to bottom of parent view
    yourView.right() // pin to parent's right-side

    yourView.pinSides() // pin to parent's left & right sides
    yourView.pinAll() // pin to parent on all sides

Pinning With Insets

    yourView.top(22) // pin to top of parent view inset by 22
    yourView.left(10) // pin to parent's left-side inset by 10
    yourView.bottom(30) // pin to bottom of parent view inset by 30
    yourView.right(10) // pin to parent's right-side inset by 10

    yourView.pinSides(10) // pin to parent's sides inset by 10 on left & right
    yourView.pinAll(20) // pin to parent sides inset by 20 on all sides

Positioning

    yourView.vertical() // position center vertical Y in superview
    yourView.horizontal() // position center horizontal X in superview
    yourView.middle() // postion center vertical & horizontal in superview

Animation & Runtime Variable Constraints

The functions top, left, bottom, right, width, and height all return optional NSLayoutConstraint which can be adjusted at runtime by direct assignment or animation.


    // get the contraint
    let leftConstraint = yourView.left()

    // be sure screen is fresh
    parentView.layoutIfNeeded()

    // assign new inset value
    leftConstraint?.constant = 100

    // take 2 seconds to slide the view to the right by 100
    UIView.animate(withDuration: 2) {
        self.parentView.layoutIfNeeded()
    }

See include Example.

Requirements

  • iOS 10.0+
  • Xcode 9

Author

ziligy, [email protected]

License

LucidLayout is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "LucidLayout",
    "version": "0.9.2",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "homepage": "https://github.com/ziligy/LucidLayout",
    "authors": {
        "ziligy": "[email protected]"
    },
    "summary": "Framework by ziligy",
    "source": {
        "git": "https://github.com/ziligy/LucidLayout.git",
        "tag": "0.9.2"
    },
    "source_files": "LucidLayout/Classes/**/*",
    "platforms": {
        "ios": "10.0"
    },
    "swift_version": "4.0"
}

Pin It on Pinterest

Share This