The Only UIStackView Guide You Will Ever Need

Swerve Auto Layout

Steven Curtis
5 min readJul 7, 2020
Photo by Kimberly Farmer on Unsplash

Prerequisites:

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

--

--

Responses (3)