How to show a popover view
About 2 min
How to show a popover view êŽë š
SwiftUI by Example
Back to Home
How to show a popover view | SwiftUI by Example
How to show a popover view
Updated for Xcode 15
SwiftUI has a dedicated modifier for showing popovers, which on iPadOS appear as floating balloons and on iOS slide onto the screen like a sheet.
To show a popover you need some state that determines whether the popover is currently visible, but thatâs about it â unlike alerts and action sheets, popovers can contain any kind of view you want. So, just place whatever you need inside the popover and SwiftUI will take care of the rest.
For example, this shows a popover view when a button is tapped:
struct ContentView: View {
@State private var showingPopover = false
var body: some View {
Button("Show Menu") {
showingPopover = true
}
.popover(isPresented: $showingPopover) {
Text("Your content here")
.font(.headline)
.padding()
}
}
}<
Similar solutionsâŠ
SwiftUI tips and tricks | SwiftUI by Example
SwiftUI tips and tricks
How to show an alert | SwiftUI by Example
How to show an alert
How to show multiple alerts in a single view | SwiftUI by Example
How to show multiple alerts in a single view
How to show a menu when a button is pressed | SwiftUI by Example
How to show a menu when a button is pressed
How to show different images and other views in light or dark mode | SwiftUI by Example
How to show different images and other views in light or dark mode