The Only UIStackView Guide You Will Ever Need
Swerve Auto Layout
Prerequisites:
- Knowledge of how to create an iOS app is required for this tutorial
- Since a UIStackView is an Array, knowledge of that data structure is assumed
Terminology
UIStackView: An interface for laying out objects horizontally or vertically
The world of constraints and Auto Layout is tricky to some. The addition of constraints and layout can be tricky, and especially so if you require putting your views into a complex layout of some sort. The solution? Stack views are there to rescue you.
You might prefer to use Interface Builder or programatic means to add UIStackView into your project. It doesn’t matter: this article has you covered in either way.
The way a Stack View (UIStackView
) displays subviews is defined by the following properties, which at runtime create the constraints necessary to create the Stack View.
These properties are:
axis: The axis along which the subviews are laid out, either .horizontal or .vertical
distribution: The distribution of arranged views along the axis
spacing: The distance in points between the adjacent edges of the stack view’s arranged views