Waranchit Chaiwong

Mar 16, 2021

3 min read

SwiftUI The series: Layout 101

View Protocol


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.


Photo by https://ichi.pro


photo by google.com
example VStack alignment attribute


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


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

2. Horizontal stack(HStack)


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


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