gpt4 book ai didi

SwiftUI - 带列表的段控制

转载 作者:行者123 更新时间:2023-12-03 18:29:32 25 4
gpt4 key购买 nike

我正在尝试制作一个处理列表和/或 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com