Working with stack views
UIStackView
is one of the coolest features introduced in iOS 9.0 for developers. It was a hassle to arrange groups of views horizontally or vertically. You had to get your hands dirty with a lot of Auto Layout constraints to arrange these views properly. UIStackView
makes arranging subviews horizontally or vertically easier without you worrying about Auto Layout. Although you don't need to use Auto Layout to arrange your views, as its UIStackview's job, you still need to use Auto Layout to define position and size of the stack view itself. If you're still not convinced about the magic that UIStackView
does, you have to give it a shot.
How to do it
As usual, let's create a new Xcode project with Single View template and name it
StackViews
.Open the storyboard file and select the view controller and change its size to iPhone 4-inch.
From Object Library, drag a Vertical stack view and add it as a subview.
Change its frame to
(X = 20, Y = 20, Width = 280)
.We need to add constraints...