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.
Apply the sizing with presentationSizing(.fitted)
FittedPresentationSizingis installed by callingpresentationSizing(_:)on the root view inside the presentation and passing the symbol's static accessor.fitted. In the example this modifier is attached to the presentedVStack, telling the sheet to derive its dimensions from that subtree rather than from a default sheet height.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 theImage, headlineText, and descriptionText—not on theText("Tap to present")that triggers the sheet.Let the content's ideal size drive the result
FittedPresentationSizingresolves the presentation to the ideal size that the content reports through normal SwiftUI layout. The.padding()andspacing: 12on theVStack, along with the intrinsic sizes of theImageand the wrappedText, are exactly what the fitted presentation reads to choose its final width and height.Swap among the PresentationSizing siblings
Because
.fittedis one conforming value ofPresentationSizing, you can exchange it for siblings like.pageor.formthrough the samepresentationSizing(_:)call without restructuring the sheet. This makesFittedPresentationSizingthe content-driven option in a small family of interchangeable sizing strategies.
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.
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)
}
}
}