Waranchit Chaiwong

Mar 16, 2021

3 min read

SwiftUI The series: Layout 101

View Protocol

Layout

The body property(View protocol) must return one view . If you would like to display multiple view on user interface, you can use Stack for group multiple views in one single view.

Stack

Photo by https://ichi.pro

VStack

photo by google.com
example VStack alignment attribute

HStack

photo by google.com

By default, the view in a horizontal stack are aligned to the center and positioned with standard space in between (usually 8 points)

example HStack alignment attribute

Spacer

The alignment options available for VStack and HStack views align the view in the opposite axis

2. Horizontal stack(HStack)

Group

The purpose of the Group is to group multiple views that applying the same modifier

below, this is an example for creating views that using the same modifier.

As the example above, you can see that multiple views are using the same modifier that Causing redundant modifiers.

You can be using Group to reduce redundant modifier

References

As the content above, that’s layout fundamental. The next episode, I’m telling about State on SwiftUI. Please to be continued.