SwiftLayout 4.0.0

SwiftLayout 4.0.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Aug 2017
SwiftSwift Version 4.0
SPMSupports SPM

Maintained by Shaps.



Note

By default Swift Layout is now using Swift 3.0. You can install either 3.0 or 2.2 version as follows:

Swift 3.0
pod 'SwiftLayout'

Swift 2.3 - Not Supported

Swift 2.2
pod 'SwiftLayout', '1.3.1'


Often we have to use AutoLayout in our apps. In fact sometimes, we can't even use Interface Builder. Which means we need to add these programmatically.

I had previously done this manually, even occassionally used a 3rd party lib/pod. There are some great libs out there, but I wanted to build my own. Both for my own understanding and also to provide a cleaner interface that made programmatic AutoLayout easy.

Introducing SwiftLayout

import SwiftLayout

class ViewController: UIViewController {

    override func viewDidLoad() {
      super.viewDidLoad()

      let views = [ addView(), addView(), addView() ]
	  views.distribute(along: .vertical, in: view)
	  views.size(width: 100, height: 50)
	  views.align(axis: .horizontal, in: view)

      let label = UILabel()
      view.addSubview(label)
      label.pin(edge: .Left, to: .Right, of: view, margin: 15)
    }

}

Usage

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

Installation

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

pod "SwiftLayout"

Author

Shaps Mohsenin, [email protected]

License

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

Attributes

Icon: Cluster by Thomas Helbig from the Noun Project