This is part of the "iOS User Interfaces" learning path. View Path

Layout in iOS

Dec 10 2019 · Video Course (2 hrs, 15 mins) · Beginner

SwiftUI and UIKit have different systems for layout. You'll learn about both in this course! For SwiftUI, that means Stacks and Alignment. For Auto Layout, it's Stack Views and Constraints, in Interface Builder.

4.1/5 13 Ratings

Version

  • Swift 5.1, iOS 13, Xcode 11

Layout in SwiftUI

Introduction

2:05 Free

This course is for learning the fundamentals of layout in SwiftUI and UIKit. Here, we'll go over what you'll learn for SwiftUI. For UIKit, head to Part 2.

1

Stack alignment occurs perpendicularly to the primary axis of a Stack: use VerticalAlignment for HStacks, and HorizontalAlignment for VStacks.

2

Recreate a section of the profile layout from the Tweetbot Twitter client using Text and Image Views in nested Stacks.

3

Stacks use Alignment Guides to match up each of their children based on a point along their perpendicular axis. If the defaults don't cut it, supply your own!

4

When you want to line up guides of particular views, but those views are inside of different stacks, custom alignments are the simplest solution.

5

Use custom alignment guides to line up specific points of interest in images with guide points of text views.

6

ZStacks

9:00

Now that you've mastered the first two dimensions, it's time to tackle the third! ZStacks have much in common with the HStacks and VStacks you know and love.

7

GeometryReader is a container view that doesn't perform stacking. Instead, its children incorporate information about it by way of the GeometryProxy structure.

8

In this final SwiftUI layout challenge, implement a badge layout that requires thinking in all three axes.

9

Conclusion

1:38

Get some recommendations on where to go for more SwiftUI layout learning. Then go over the similarity in SwiftUI's and UIKit's layout systems.

10

Stack Views

An introduction to what Auto Layout is and why you need to use it in your apps.

11

Autoresizing is the predecessor to Auto Layout. It’s simpler, and sometimes, effective! Dive into the “mask of flexibilities”!

12

Create your first stack view and learn about some basic properties to adjust the layout.

13

Use everything you’ve learned about Stack Views so far to recreate a few simple view layouts from reference images.

14

What is Intrinsic Content Size? Find out how Auto Layout uses the intrinsic size of a view to determine layout.

15

Stack views inside of stack views! Unlock more power of stack views by nesting them to create complex layouts.

16

Learn about the options for stack view alignment and distribution and how they work to arrange your views.

17

Practice everything you’ve learned so far about stack views by implementing a complex, nested layout.

18

Conclusion

0:26

Review what you’ve learned in this section and find out what’s coming up next.

19

Constraints

Get a solid introduction to Auto Layout constraints, and find out what you’ll learn in this section.

20

The Add New Constraints UI in Interface Builder packs a whole lot of Auto Layout power into a compact popup.

21

Right- or control-click dragging between two views is another great option for creating Auto Layout constraints.

22

Convert the type of your stack view constraints, getting practice with Auto Layout while gaining more control over the stack view’s width.

23

This is an overview of the UI that Xcode offers for editing constraints that have already been created.

24

Just like with Swift, you’ll get into temporary, problematic states when working in Interface Builder, before your constraints are ready. Let’s solve a few!

25

Conclusion

2:03

Review what you’ve learned in this section, and pick up some parting tips for using Auto Layout in your apps.

26

Who is this for?

This course is in our iOS and Swift for Beginners learning path. You're ready for this course if you're working through that learning path in order, or you're someone who has a bit of iOS and Swift experience: enough to know the basics of putting views onscreen in a SwiftUI- or UIKit-based app.

The first part of the course is all SwiftUI. To begin with, you'll start working with Alignments, which are key to making the most out of Stacks. You'll learn how to use built-in alignment guides, and create your own custom ones.

Moving on from Alignment, the SwiftUI material concludes with the ZStack and GeometryReader structures.

The other two parts of the course cover the basics of Auto Layout in UIKit: UIStackView and constraints. Auto Layout's simple predecessor, Autoresizing, is also covered.

Throughout the course, you'll practice everything you learn with hands-on challenges, recreating the kind of scalable layouts you'll find in popular iOS apps.

This course isn’t suited for intermediate or advanced developers. If that’s you, check out our intermediate or advanced video courses for more ways to level-up your developer skills!

Covered concepts

  • SwiftUI Stacks
  • Stack Alignment
  • alignmentGuide Modifier
  • AlignmentID Protocol
  • GeometryReader + GeometryProxy
  • UIKit Stack Views
  • Interface Builder
  • Intrinsic Content Size
  • Auto Layout Constraints
  • Autoresizing

Contributors

Comments