SwiftUI操作表选择器

SwiftUI操作表选择器,swiftui,picker,swiftui-actionsheet,Swiftui,Picker,Swiftui Actionsheet,我试图在SwiftUI中创建一个操作表,该操作表在按下按钮后显示,允许用户通过选择器选择并返回项目(如下所示) 有关于如何做的提示吗 谢谢 输出 输出 struct ContentView: View { init() { UITableView.appearance().separatorColor = .clear } var inputArray = ["100","101","102"] @State var slectedSegmant = "ActionShee

我试图在SwiftUI中创建一个操作表,该操作表在按下按钮后显示,允许用户通过选择器选择并返回项目(如下所示)

有关于如何做的提示吗

谢谢

输出

输出

struct ContentView: View {
  init() {
    UITableView.appearance().separatorColor = .clear
   }
var inputArray = ["100","101","102"]
@State var slectedSegmant = "ActionSheet"
@State var slectedObj = "101"
@State var enableSheet = false
var test = false
var body: some View {
    ZStack {
        VStack(spacing: 10) {
            Picker(selection: $slectedSegmant, label: Text("Segment")) {
                Text("Alert").tag("Alert")
                Text("ActionSheet").tag("ActionSheet")
            }.pickerStyle(SegmentedPickerStyle())
                .labelsHidden()
                .padding(EdgeInsets.init(top: 50, leading: 10, bottom: 0, trailing: 10))

            Text("Alert & Pickers")
                .font(Font.system(size: 35, design: .rounded))
                .fontWeight(.bold)
                .frame(maxWidth: .infinity, alignment: .leading)
                .padding(.horizontal)

            List((0...50),id: \.self) { input in
                ZStack {
                    HStack(spacing: 10) {
                        Image(systemName: "book")
                            .font(.title)
                            .padding(.leading, 10)
                        VStack(alignment: .leading, spacing: 5, content: {
                            Text("Simple")
                            Text("3 different buttons")
                        })
                        Spacer()
                    }.padding(.vertical)
                        .frame(maxWidth:.infinity)
                        .background(RoundedRectangle(cornerRadius: 10).foregroundColor(Color.white).shadow(radius: 1.5)
                        )

                    Button(action: {
                        self.enableSheet = true
                    }) {
                        Text("")
                    }
                }
            }.padding()
        }.blur(radius: $enableSheet.wrappedValue ? 1 : 0)
            .overlay(
                $enableSheet.wrappedValue ? Color.black.opacity(0.6) : nil
            )
       if $enableSheet.wrappedValue {
            GeometryReader { gr in
                VStack {
                    VStack {
                        Text("PickerView")
                            .font(.headline)
                            .foregroundColor(.gray)
                            .padding(.top, 10)
                        Text("Prefered ContentHeight")
                            .padding(.top, 5)
                        Picker("test", selection: self.$slectedObj) {
                            Text("100").id("100")
                            Text("101").id("101")
                            Text("101").id("102")
                        }.labelsHidden()
                    }.background(RoundedRectangle(cornerRadius: 10)
                        .foregroundColor(Color.white).shadow(radius: 1))
                    VStack {
                        Button(action: {
                            debugPrint("Done Selected")
                            self.enableSheet = false
                        }) {
                            Text("Done").fontWeight(Font.Weight.bold)
                        }.padding()
                            .frame(maxWidth: gr.size.width  - 90)
                            .background(RoundedRectangle(cornerRadius: 10)
                            .foregroundColor(Color.white).shadow(radius: 1))

                    }
                }.position(x: gr.size.width / 2 ,y: gr.size.height - 200)
            }
        }
    }.edgesIgnoringSafeArea(.all)
  }
 }