SwiftUI: Adjust items spacing in Stacks

--

There are multiple ways to add spacing in stack items:

Spacing: Stacks have built in support to add spacing between items

HStack(spacing: 10) {
Text("Learning")
Text("Swift")
}

Divider: One way is to use Divider to add spacing along with a visible separator line in stack items.

HStack {
Text("Learning")
Divider()
Text("Swift")
}

Spacer: Another way is to use Spacer which will move views to edges giving enough space between items

HStack {
Text("Learning")
Spacer()
Text("Swift")
}

--

--

Priyanka Saroha

iOS developer with almost 9 years of rich experience which includes a good knowledge of ObjectiveC, Swift, SwiftUI and AR.