Platformsios 10.0


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


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.


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

pod 'LucidLayout'


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


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


All pinning is relative to the inside the parent view. // 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 // 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


    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

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

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

See include Example.


  • iOS 10.0+
  • Xcode 9


ziligy, [email protected]


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": "",
    "authors": {
        "ziligy": "[email protected]"
    "summary": "Framework by ziligy",
    "source": {
        "git": "",
        "tag": "0.9.2"
    "source_files": "LucidLayout/Classes/**/*",
    "platforms": {
        "ios": "10.0"
    "swift_version": "4.0"

Pin It on Pinterest

Share This