One of the views that keeps getting great improvements over time in SwiftUI is the sheet; the view that appears modally and gives us the space to present content above other content temporarily. Presenting a sheet is quite a common task when developing apps for any platform. SwiftUI provides a series of view modifiers that allow us to override its default appearance and behavior, so we can customize sheets to better match the appearance and needs of our apps.
One of the main distinguishing features of sheets is their placement. Until recently, SwiftUI would automatically decide where to present a sheet based on the platform and the available space, without giving us any control over its position. However, starting with iPadOS 27 and iOS 27, we can actually specify the placement of sheets, choosing among three values: leading, center, and trailing.
Note
There’s also a fourth option, automatic, which lets the system decide about the placement.
Next, we’ll explore how that’s possible on iPadOS, and how we can make it also work on iOS, along with some other useful details.
The presentation placement modifier
I just mentioned in the introduction that there are essentially three possible placements for sheets; leading, center, and trailing. Programmatically, such a placement is a PresentationPlacement value, where PresentationPlacement is a structure that provides the following static properties:
automatic: When used, the system decides about the best placement for the sheet.leading: The sheet appears close to the leading edge of the view.center: The sheet appears at the center of the view, just as we’ve known it so far.trailing: The sheet appears close to the trailing edge of the view.
To see how we can change the placement of a sheet, let's use a really simple example:
VStack {
Picker("Sheet Placement Options", selection: $sheetPlacement) {
Text("Automatic")
.tag(PresentationPlacement.automatic)
Text("Leading")
.tag(PresentationPlacement.leading)
Text("Center")
.tag(PresentationPlacement.center)
Text("Trailing")
.tag(PresentationPlacement.trailing)
}
.pickerStyle(.segmented)
.frame(maxWidth: 450)
Button("Present Sheet") {
presentSheet.toggle()
}
.buttonStyle(.glassProminent)
.padding(.top)
}
.padding()
.sheet(isPresented: $presentSheet) {
sheetContent
}
A picker provides the available placement values in a segmented control, which we'll use to specify the final placement of the sheet we're presenting. The selected placement is stored in the following state property of type PresentationPlacement:
@State private var sheetPlacement: PresentationPlacement = .automatic
And here’s the presentSheet property that controls the sheet’s presentation:
@State private var presentSheet = false
The sheet is presented with the sheet(_:content:) modifier and its actual content is not important here. sheetContent is the next computed property:
var sheetContent: some View {
VStack {
Text("Sample sheet content")
.font(.title)
Text("This sheet appears in various placements. 😍")
.font(.title2)
Button("Dismiss") {
presentSheet.toggle()
}
.padding(.top)
}
}
If we run the above on an iPad or the Device Hub (the Simulator), the sheet will appear in its usual position. To change that, all we have to use is the presentationPlacement(_:) modifier (new as of OS 27):
.sheet(isPresented: $presentSheet) {
sheetContent
.presentationPlacement(sheetPlacement)
}
See that we provide the sheetPlacement property as an argument, the value of which we can change using the picker. However, we can hardcode a value too when necessary.
The above modifier now allows us to show the sheet in different positions:
Changing sheet placement on iOS
While the presentationPlacement(_:) modifier works as expected on iPad, it doesn’t have an immediate effect on iPhone. That's because SwiftUI adapts the presentation of sheets based on the available space, and this can prevent us from changing their placement.
To make the placement work on iPhone in landscape orientation, we need to use another modifier, the presentationCompactAdaptation(_:), passing .sheet as its argument. By doing that, we ask SwiftUI to keep the sheet presentation style, even in a compact size class, instead of automatically adapting it to another presentation style.
.sheet(isPresented: $presentSheet) {
sheetContent
.presentationPlacement(sheetPlacement)
.presentationCompactAdaptation(.sheet)
}
Alternatively, we can pass .none as the argument, which tells SwiftUI not to apply its usual compact adaptation.
The bottom line is that both options allow the presentationPlacement(_:) modifier to take effect on iPhone. In our example, the different placements become visible in landscape orientation. In portrait orientation, the sheet occupies the available width, so changing its placement doesn’t produce a visible difference.
Combining sheet placement with other modifiers
As you'd expect, the placement modifier can co-exist with other modifiers applied to the contents of the sheet. This way, any additional configuration or customization remains in effect regardless of the sheet’s placement.
For example:
.sheet(isPresented: $presentSheet) {
sheetContent
.presentationPlacement(sheetPlacement)
// Other modifiers along with the .presentationPlacement.
.presentationDetents([.fraction(0.35), .large])
.presentationCornerRadius(12)
}
Wrapping up
The presentationPlacement(_:) modifier is a welcome addition, as it allows us to present sheets in positions other than the default one, keeping more content visible behind. Available since iPadOS 27 and iOS 27, it works as expected on iPad. On iPhone, we also need to use the presentationCompactAdaptation(_:) modifier, so we can reposition sheets in landscape orientation. Thanks for reading!