There are 2 system ways to do layout in iOS.
Don’t use frame based layouts unless you have to. Especially when it comes to supporting multiple size classes and such, that’s way more effort than it’s worth.
In general, I prefer this for laying out code:
- Nibs w/ Autolayout
- Code w/ Autolayout
- Code w/ frames
From NSLayoutConstraint’s api:
Each constraint is a linear equation with the following format:
item1.attribute1 = multiplier * item2.attribute2 + constant
NSLayoutConstaintis the underlying api for specifying layout constraint. Everything else essentially gets converted to these when you use them.
NSLayoutAnchor, introduced in iOS 9, is a factory class that makes it way nicer to specify layout constraints, without having to resort to visual format language.
NSLayoutConstraintVisual Format Language, is used in a class constructor for
Third Party Frameworks
- PureLayout provides a declarative interface for creating and installing layout constraints. It works as categories on NS/UIView and NSArray.