SwiftUI - 带列表的段控制

SwiftUI - Segment Control with Lists

我正在尝试制作一个处理列表的段控件 and/or 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)")


            }
        }
    }
}

我怎样才能拥有在列表 and/or Vstack 之间切换的段控件?

是的!这很简单。像这样:

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)")
                    }
                }
            }
        }
    }
}