A µframework with the purpose to be the most brief and readable way to declare or apply a AutoLayout NSLayoutConstraint in Swift.
With TinyLayout you can stop doing this:
let superview = self.view
let view = UIView()
view.setTranslatesAutoresizingMaskIntoConstraints(false)
superview.addSubview(view)
superview.addConstraint(NSLayoutConstraint(item: view, attribute: .Top, relatedBy: .Equal, toItem: superview, attribute: .Top, multiplier: 1, constant:0))
And start doing this:
let superview = self.view
let view = UIView()
superview.addSubview(view)
(view,.Top)|=|(superview,.Top)
If you’re using Carthage, simply add
TinyLayout to your Cartfile
:
github "rubenroques/TinyLayout"
The simplest version, without multipliers or constraints.
//Add a NSLayoutConstraint to the view.superview
(view,.Top)|=|(superview,.Top)
//Create a NSLayoutConstraint variable
let layoutConstraint = (view,.Top)|=|&(superview,.Top)
The default values are constant = 0
and multiplier = 1
.
With a constant value.
//Add a NSLayoutConstraint to the view.superview
(view,.Top)|=|(superview,.Top, 50)
(view,.Left)|=|(superview,.Left, -100)
//Create a NSLayoutConstraint variable
let layoutConstraintTop = (view,.Top)|=|&(superview,.Top, 50)
let layoutConstraintLeft = (view,.Left)|=|&(superview,.Left, -100)
With a constant value and a multiplier.
//Add a NSLayoutConstraint to the view.superview
(view,.Top)|=|(superview,.Top, 1.2, 50)
(view,.Left)|=|(superview,.Left, 2, -100)
//Create a NSLayoutConstraint variable
let layoutConstraintTop = (view,.Top)|=|&(superview,.Top, 1.2, 50)
let layoutConstraintLeft = (view,.Left)|=|&(superview,.Left, 2, -100)
- Finish Roadmap :)
- ["You should be testing your library."] (http://guides.cocoapods.org/making/using-pod-lib-create.html#choosing-a-test-framework)
- Create a
typealias
to avoid repeat the long tuples used in the functions parameter names - Improve demo app
- Add support to fallback constrains using an array of UIView
(view,.Top)|=|([superview, labelA, labelB],.Top)
- Create func to set the NSLayoutConstraint priority in the declaration
- Migrate from UIView to View to add support for AppKit
If you find any problem with TinyLayout, submit an issue.
TinyLayout it's completely open to new ideas and suggestions. Create an issue and lets discuss what you have in mind.
This project is licensed under the terms of the MIT license. See the LICENSE file.