Sheet in SwiftUI (iOS 15+)

DevTechie
DevTechie
Published in
5 min readOct 27, 2022

--

SwiftUI sheet modifier is used when we want to present a modal view to the user when a provided boolean value becomes true.

In this article, we will explore sheet modifier.

Let’s create an example to work with.

struct DevTechieSheetExample: View {
var body: some View {
VStack {
Text("DevTechie")
.font(.largeTitle)
.foregroundColor(.white)
.padding()
.frame(maxWidth: .infinity)
.background(.orange)

Spacer()

Text("Press the button to launch a sheet.")

Button("Tap me") {

}

Spacer()
}
}
}

In order to add a sheet, we need a boolean variable which we can pass as binding value to isPresented parameter of sheet modifier. We will add a State property called showSheet.

@State private var showSheet = false

Next, we will add sheet modifier to the Button and toggle the showSheet State variable. As the content trailing closure for the sheet modifier, we will simply create a…

--

--