Im trying to make a Segment Control that handles Lists and/or Vstacks
I was able to make a Segment Control with text, but not Lists
import SwiftUI
struct MaterialSegmentControl : View {
@State private var MaterialType = 0
var body: some View {
NavigationView {
VStack {
SegmentedControl(selection: $MaterialType) {
Text("Style").tag(0)
Text("Text").tag(1)
Text("Arrange").tag(2)
}
Text("Value: \(MaterialType)")
}
}
}
}
How can I have a Segment Control that switched between Lists and/or Vstacks?
Yes! It's pretty straightforward. Something like this:
struct MaterialSegmentControl : View {
@State private var MaterialType = 0
var body: some View {
NavigationView {
VStack {
SegmentedControl(selection: $MaterialType) {
Text("Style").tag(0)
Text("Text").tag(1)
Text("Arrange").tag(2)
}
if MaterialType == 0 {
List {
Text("Hi")
Text("\(MaterialType)")
}
} else if MaterialType == 1 {
List {
Text("Beep")
Text("\(MaterialType)")
}
} else {
List {
Text("Boop")
Text("\(MaterialType)")
}
}
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With