From the course: iOS Development: Auto Layout Programmatically
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
The distribution property and size - iOS Tutorial
From the course: iOS Development: Auto Layout Programmatically
The distribution property and size
- [Instructor] Alignment sets spacing and alignment perpendicular to the axis. Distribution sets spacing along the axis. Though this is a bit more subtle than alignment. Stop the app. And take a look at the code for the stack view. Like fill on the alignment, fillEqually is the basic automatic mode. It creates constraints that pin each subview to each other and sets the size to be equal for all the subviews. For a vertical axis that's the height, for a horizontal the width. Currently the subviews are flush with one another. You can add space with the spacing property of UIStackView. Under distribution here, add this line. StackView.spacing equals 10. Go ahead and run the app. Hit Maki Rolls and you'll see you're getting it at a spacing of 10 between each one of our elements. Now you can also get unequal spacing, and that's a method called setCustomSpacingAfter. You can go ahead and stop this. And I'm gonna do another stack view dot, and this is gonna be setCustomSpacing with a CGFLoat…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.