SwiftUI: Adjust items spacing in Stacks
Sep 9, 2023
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")
}