Chapter 7

Formatting Your User Interface

IN THIS CHAPTER

check Laying out your views

check Justifying views

check Inserting spacing between views

check Animating with ZStack

check Displaying views for collecting user inputs

check Logically grouping views

In the previous chapters, I show you how the various views in SwiftUI help you to create compelling user interfaces (UIs) in your iOS apps. I also show you a few ways to lay out your views using the VStack, HStack, and ZStack views. In this chapter, I explain these views in more detail and tell you how they allow you to lay out your UI in different ways.

Laying Out Views Using Stacks

In SwiftUI, you describe your app's UI in the view’s body property:

struct ContentView: View {

var body: some View {

// your UI here

}

}

The body property only returns a single view, so no matter how complex your UI is, it needs to return only one single view. To create a compelling ...

Get SwiftUI For Dummies now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.