Home > AI > IOS > SwiftUI >

popover

popover(isPresented:attachmentAnchor:arrowEdge:content:)

Presents a popover when a given condition is true.

Example:


struct ContentView: View {
    
    @State var isShowingPopover = false
    
    var body: some View {
        NavigationView {
            Text("Hello Good")
                .toolbar {
                    ToolbarItem(placement: .navigationBarTrailing) {
                        Button("Popover") {
                            isShowingPopover.toggle()
                        }
                        .popover(isPresented: $isShowingPopover) {
                            Text("Hi from a popover")
                                .padding()
                                .frame(width: 320, height: 100)
                                .onTapGesture {
                                    isShowingPopover = false
                                }
                        }
                    }
                } // end toolbar
        } // end NavigationView
    } // end body
}

Leave a Reply