Find these examples and more in the Example Project.
Installation
CocoaPods
TinyConstraints is available through CocoaPods. To install
it, simply add the following line to your Podfile:
pod "TinyConstraints"
Carthage
TinyConstraints is available through Carthage. To install
it, simply add the following line to your Cartfile:
github "roberthein/TinyConstraints"
Swift Package Manager
TinyConstraints is available through Swift Package Manager. To install
it, in Xcode 11.0 or later select File > Swift Packages > Add Package Dependency... and add TinyConstraints repository URL:
TinyConstraints is the syntactic sugar that makes Auto Layout sweeter for human use.
Features
translatesAutoresizingMaskIntoConstraints
becauseTinyConstraints
does it for you.Examples
Edges
Attaching a view to its superview with
NSLayoutConstraint
:with
TinyConstraints
:or:
Center
Constraining the center of a view to its superview with
NSLayoutConstraint
:with
TinyConstraints
:or:
Basic Use
Typealiases
TinyConstraints
gives you convenient and tiny typealiases for handling constraints.Constraint
=NSLayoutConstraint
Constraints
=[NSLayoutConstraint]
Equal and Unequal Anchors
This constraints the
top-anchor
of the view to thetop-anchor
of the superview:This constraints the
top-anchor
offirstView
to thebottom-anchor
ofsecondView
:Constrain to Superview
Often you need to constrain a view to it’s superview, with TinyConstraints you can do this super easy:
Or only one edge:
Or you can attach all edges except one, like this:
Relation and Priority
For almost all constraints you can set the
relation
andpriority
properties. The default relation is.equal
and the default priority is.required
:Storing Constraints
Here we create a set of inactive constraints and store these to our property:
Activation and Deactivation
Besides the default
NSLayoutConstraint
activation,TinyConstraints
also provides a way to activate a set of constraints:You can also do this in an animation:
Animating Constraint Constants
Here we add a height constraint to a view, store it and animate it later:
Stack
Stack provides a way of constraining views together in a superview:
Find these examples and more in the Example Project.
Installation
CocoaPods
TinyConstraints is available through CocoaPods. To install it, simply add the following line to your Podfile:
Carthage
TinyConstraints is available through Carthage. To install it, simply add the following line to your Cartfile:
Swift Package Manager
TinyConstraints is available through Swift Package Manager. To install it, in Xcode 11.0 or later select
File
>Swift Packages
>Add Package Dependency...
and add TinyConstraints repository URL:Tutorials
Here are some video tutorials made by Alex Nagy.
Suggestions or feedback?
Feel free to create a pull request, open an issue or find me on Twitter.