NEW BOOK! Swift Gems: 100+ tips to take your Swift code to the next level. Learn more ...NEW BOOK! Swift Gems:100+ advanced Swift tips. Learn more...
Quick Tip Icon
Quick Tip

Present a form sheet in SwiftUI

For a while, presenting a form sheet in SwiftUI, equivalent to the UIModalPresentationStyle.formSheet, was a challenge. Now, with the new presentationSizing() modifier, we can easily achieve this using the form sizing option.

Here's a simple example to demonstrate how to present a form sheet in SwiftUI on iPadOS 18:

.sheet(isPresented: $showSheet) {
    Text("Form Sheet")
        .font(.title)
        .presentationSizing(.form)
}

In this example, the presentationSizing(.form) modifier ensures that the sheet is presented as a form sheet, providing a more compact and centered appearance on larger devices.

Screenshot of a form sheet on iPad simulator

SwiftUI now also allows for custom sizing logic for sheets. This opens up new possibilities for tailoring the presentation of our views to better fit our app's design.

For more examples and detailed information, check out the PresentationSizing documentation.

Swift Gems by Natalia Panferova book coverSwift Gems by Natalia Panferova book cover

Level up your Swift skills!$35

100+ tips to take your Swift code to the next level

Swift Gemsby Natalia Panferova

  • Advanced Swift techniques for experienced developers bypassing basic tutorials
  • Curated, actionable tips ready for immediate integration into any Swift project
  • Strategies to improve code quality, structure, and performance across all platforms

Level up your Swift skills!

100+ tips to take your Swift code to the next level

Swift Gems by Natalia Panferova book coverSwift Gems by Natalia Panferova book cover

Swift Gems

by Natalia Panferova

$35