TechnologiesSwiftUIPresentation and Dialogs

PresentationDetent struct

iOSmacOStvOSwatchOSvisionOSiOS 16.0+✓ renders

A type that represents a height where a sheet naturally rests.

How it works

A PresentationDetent describes a height at which a presented sheet comes to rest, letting a sheet stop at a partial size instead of always covering the full screen. Reach for it when you want a sheet that a person can drag between a compact, content-peeking state and a fully expanded one, while still seeing the view behind it. SwiftUI ships a set of standard detents as type properties, and you supply them to a sheet to define its allowed resting positions.

  1. Use the standard detents as type properties

    PresentationDetent exposes its common positions as static members rather than something you construct by hand. .medium rests the sheet at roughly half the available height, and .large expands it to the full sheet height — the two values passed in this example.

  2. Declare the allowed positions with presentationDetents(_:)

    You attach detents to a sheet's content with the presentationDetents(_:) modifier, which takes a set of PresentationDetent values describing every height the sheet is permitted to rest at. Here .presentationDetents([.medium, .large]) gives the sheet two stops, so it opens partway and can be dragged up to full height.

  3. Order doesn't pick the initial height — the set does

    Because the argument is a Set, the collection only defines which detents exist, not a sequence; the sheet starts at the smallest detent in the set. Listing .medium and .large means the sheet appears at the medium height first, with the large height available by dragging.

  4. Pair it with presentationDragIndicator(_:) so the resize affordance is visible

    Detents are most discoverable when the sheet shows a grabber the person can pull. .presentationDragIndicator(.visible) draws that handle, signaling that the sheet defined by the PresentationDetent set can move between its medium and large rest heights.

  5. Custom heights with .height(_:) and .fraction(_:)

    Beyond the standard cases, PresentationDetent offers .height(_:) for a fixed point value and .fraction(_:) for a proportion of the container, so you can define your own resting positions — for instance swapping .medium for .fraction(0.3) in the set passed to presentationDetents(_:).

Try it — Change .presentationDetents([.medium, .large]) to .presentationDetents([.height(120), .large]) and watch the sheet open at a fixed 120-point peek before it can be dragged to full height.

Example & preview

Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.

PresentationDetent.swift
struct PresentationDetentDemo: View {
    @State private var showSheet = true

    var body: some View {
        Text("Detail behind the sheet")
            .padding()
            .sheet(isPresented: $showSheet) {
                VStack(spacing: 12) {
                    Text("Medium Detent Sheet")
                        .font(.headline)
                    Text("Resting at half height.")
                        .foregroundStyle(.secondary)
                }
                .padding()
                .presentationDetents([.medium, .large])
                .presentationDragIndicator(.visible)
            }
    }
}
Live preview
Detail behind the sheet Medium Detent Sheet Resting at half height.
Detail behind the sheet Medium Detent Sheet Resting at half height.
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →