Black Friday deal: 30% off our book "Integrating SwiftUI into UIKit apps"! Learn more ...Black Friday deal:30% off "Integrating SwiftUI into UIKit apps" >>
Quick Tip Icon
Quick Tip

Show half-sheet in SwiftUI

In iOS 16 we can finally present a resizable sheet in SwiftUI. To specify which detents the sheet supports, we can use the new presentationDetents() modifier.

To present a half-sheet that can't be resized by the user, we specify a single medium detent.

struct ContentView: View {
    @State private var showSheet = false
    
    var body: some View {
        Button("Show Sheet") {
            showSheet = true
        }
        .sheet(isPresented: $showSheet) {
            Text("Sheet Content")
                .presentationDetents([.medium])
        }
    }
}
Integrating SwiftUI into UIKit Apps by Natalia Panferova book coverIntegrating SwiftUI into UIKit Apps by Natalia Panferova book cover
Black Friday offer
Our book "Integrating SwiftUI into UIKit apps" is now 30% off!

Discover various ways to adopt SwiftUI in existing UIKit projects and take full advantage of the new iOS 16 frameworks and APIs such as Swift Charts.

The offer is active until the 1st of December.

To present a sheet that can be resized between a half-sheet and a full sheet, we should add both medium and large detents.

struct ContentView: View {
    @State private var showSheet = false
    
    var body: some View {
        Button("Show Sheet") {
            showSheet = true
        }
        .sheet(isPresented: $showSheet) {
            Text("Sheet Content")
                .presentationDetents([.medium, .large])
        }
    }
}

Detents are only supported for sheets presented on iPhone or in compact horizontal size on iPad. In regular size on iPad and on the Mac, detents will be ignored.

SwiftUI also added support for some custom detents, you can find out more in PresentationDetent documentation.

If you would like to learn more about resizable sheets in SwiftUI, you can read our detailed post that covers all the functionality and limitations of the API.