How to add a TextField to Alert in SwiftUI?

前端 未结 9 1937
温柔的废话
温柔的废话 2021-02-03 21:33

Anyone an idea how to create an Alert in SwiftUI that contains a TextField?

\"sample_image\"

9条回答
  •  孤独总比滥情好
    2021-02-03 21:58

    Step1: Make root view as ZStack

    Step2: Add variable for show/hide

     @State var showAlert = false
    

    Step 3: Add this custom layout inside root view (ZStack)

      if $showAlert.wrappedValue {
                ZStack() {
                    Color.grayBackground
                    VStack {
                        //your custom layout text fields buttons 
                       
                    }.padding()
                }
                .frame(width: 300, height: 180,alignment: .center)
                .cornerRadius(20).shadow(radius: 20)
            }
    

提交回复
热议问题