Skip to content

Instantly share code, notes, and snippets.

@rubencodes
Last active February 28, 2024 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubencodes/2335417b432d8c348028c4798af02d73 to your computer and use it in GitHub Desktop.
Save rubencodes/2335417b432d8c348028c4798af02d73 to your computer and use it in GitHub Desktop.
SwiftUI Spacing Demo
@available(iOS 16.0, *)
struct SpacingDemo_Previews: PreviewProvider {
static var previews: some View {
NavigationStack {
Form {
Group {
Section {
HStack {
Spacer()
Rectangle().fill(.blue)
Spacer()
}
.background(.red)
} header: {
Text("MinLength Default, Stack Spacing Default")
}
Section {
HStack {
Spacer(minLength: 0)
Rectangle().fill(.blue)
Spacer(minLength: 0)
}
.background(.red)
} header: {
Text("MinLength Zero, Stack Spacing Default")
}
Section {
HStack(spacing: 8) {
Spacer(minLength: 0)
Rectangle().fill(.blue)
Spacer(minLength: 0)
}
.background(.red)
} header: {
Text("MinLength Zero, Stack Spacing 8")
}
Section {
HStack(spacing: 0) {
Spacer(minLength: 0)
Rectangle().fill(.blue)
Spacer(minLength: 0)
}
.background(.red)
} header: {
Text("MinLength Zero, Stack Spacing Zero")
}
Section {
HStack {
Text("Hi").background(.green)
Rectangle().fill(.blue)
Text("Hi").background(.green)
}
.background(.red)
} header: {
Text("Text, with Stack Spacing Default")
}
}
.listRowBackground(Color.clear)
.listRowSpacing(.zero)
}
.navigationTitle("Spacing Demo")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment