SwiftUI Popup弹出对话框

struct ModalPopups: View {

    @State private var showingModal = false

    var body: some View {

        ZStack {

            VStack(spacing: 20) {

                Text("Popup对话框之弹出").font(.largeTitle)

                Text("介绍").font(.title).foregroundColor(.gray)

                Text("您可以使用ZStack和State变量创建自己的模式弹出窗口。")

                    .frame(maxWidth: .infinity)

                    .padding().font(.title).layoutPriority(1)

                    .background(Color.orange).foregroundColor(Color.white)

                Button(action: {

                    self.showingModal = true

                }) {

                    Text("显示弹出alert")

                }

                Spacer()

            }

            if $showingModal.wrappedValue {

                ZStack {

                    Color.black.opacity(0.8)

                        .edgesIgnoringSafeArea(.vertical)

                    VStack(spacing: 20) {

                        Text("标题")

                            .bold()

                            .padding()

                            .frame(maxWidth: .infinity)

                            .background(Color.orange)

                            .foregroundColor(Color.blue)

                        Text("这里是详情啊")

                            .foregroundColor(Color.blue)

                            .padding()

//                        Spacer()

                        Button(action: {

                            self.showingModal = false

                        }) {

                            Text("关闭")

                        }.padding()

                    }

                    .frame(width: 300)

                    .background(Color.white)

                    .cornerRadius(20).shadow(radius: 20)

                }

            }

        }

    }

}

你可能感兴趣的:(SwiftUI Popup弹出对话框)