我正在尝试制作一个处理列表和/或 Vstacks 的段控件
我能够使用文本创建段控件,但不能使用列表
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)")
}
}
}
}
我怎样才能有一个在列表和/或 Vstacks 之间切换的段控件?
最佳答案
是的!这很简单。像这样的东西:
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)")
}
}
}
}
}
}
关于SwiftUI - 带列表的段控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56690359/