TechnologiesSwiftUIPresentation and Dialogs

FittedPresentationSizing struct

iOSmacOStvOSwatchOSvisionOSiOS 18.0+✓ renders

The size of the presentation is dictated by the ideal size of the content.

How it works

FittedPresentationSizing is a presentation sizing strategy that asks a sheet or other presentation to measure its content and adopt that content's ideal size, rather than expanding to a system default or a fixed fraction of the screen. It conforms to the PresentationSizing protocol and is the value you reach for when a presentation holds compact, self-describing content—a short form, a confirmation, a small detail panel—and you want the container to hug it instead of leaving empty space. You apply it through the presentationSizing(_:) modifier on the presented content, where it is exposed as the static member .fitted. Use it when the content's own layout should be the source of truth for how large the presentation appears.

  1. Apply the sizing with presentationSizing(.fitted)

    FittedPresentationSizing is installed by calling presentationSizing(_:) on the root view inside the presentation and passing the symbol's static accessor .fitted. In the example this modifier is attached to the presented VStack, telling the sheet to derive its dimensions from that subtree rather than from a default sheet height.

  2. Place it on the presented content, not the presenter

    The sizing must live inside the presentation's content builder so it can measure the views being shown. Here .presentationSizing(.fitted) sits in the trailing closure of .sheet(isPresented:), where it governs how the sheet wraps the Image, headline Text, and description Text—not on the Text("Tap to present") that triggers the sheet.

  3. Let the content's ideal size drive the result

    FittedPresentationSizing resolves the presentation to the ideal size that the content reports through normal SwiftUI layout. The .padding() and spacing: 12 on the VStack, along with the intrinsic sizes of the Image and the wrapped Text, are exactly what the fitted presentation reads to choose its final width and height.

  4. Swap among the PresentationSizing siblings

    Because .fitted is one conforming value of PresentationSizing, you can exchange it for siblings like .page or .form through the same presentationSizing(_:) call without restructuring the sheet. This makes FittedPresentationSizing the content-driven option in a small family of interchangeable sizing strategies.

Try it — Add more lines to the description Text("This sheet sizes itself to its content's ideal size.") and watch the fitted sheet grow taller to keep hugging the content, since .fitted tracks the content's ideal size.

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.

FittedPresentationSizing.swift
struct FittedPresentationSizingDemo: View {
    @State private var showing = true

    var body: some View {
        Text("Tap to present")
            .padding()
            .sheet(isPresented: $showing) {
                VStack(spacing: 12) {
                    Image(systemName: "square.resize")
                        .font(.largeTitle)
                    Text("Fitted Sheet")
                        .font(.headline)
                    Text("This sheet sizes itself to its content's ideal size.")
                        .multilineTextAlignment(.center)
                }
                .padding()
                .presentationSizing(.fitted)
            }
    }
}
Live preview
Tap to present Fitted Sheet This sheet sizes itself to its content's ideal size.
Tap to present Fitted Sheet This sheet sizes itself to its content's ideal size.
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →