How can I change the size of a sheet on iPad in SwiftUI

Asked on 07/31/2024

1 search

To change the size of a sheet on iPad in SwiftUI, you can use the new presentation sizing modifier introduced in the latest updates. This modifier allows you to create perfectly sized sheets with form or page, or even use custom sizing.

For more details, you can refer to the session What’s new in SwiftUI at the timestamp 02:22.

Here is a brief example of how you might use the presentation sizing modifier in SwiftUI:

.sheet(isPresented: $isSheetPresented) {
    MySheetView()
        .presentationDetents([.medium, .large])
        .presentationDragIndicator(.visible)
}

In this example, .presentationDetents([.medium, .large]) specifies the sizes that the sheet can adopt. You can customize these detents to fit your specific needs.