Displaying popovers
A popover is a view that can be displayed on screen to provide more information about a particular item. It includes an arrow pointing to the location where it originates from. You can tap on any other screen area to dismiss the popover. Popovers are typically used on larger screens such as on the iPad.In this recipe, we will create and display a popover on an iPad.
Getting ready
Create a new SwiftUI project named DisplayingPopovers
.
How to do it…
Following the pattern we've used so far in this chapter, we will first create a @State
variable whose value triggers the displaying or hiding of a popover. Then we will add a .popover()
modifier that displays the popover when the @State
variable is true
. The steps are as follows:
- Just above the
body
variable in theContentView.swift
file, add astate
variable that will be used to trigger the display of the popover:
@State private var showPopover = false
- Within the
body
variable, replace the contents with...