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])
        }
    }
}

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.

Integrating SwiftUI into UIKit Apps by Natalia Panferova book coverIntegrating SwiftUI into UIKit Apps by Natalia Panferova book cover

Check out our book!

Integrating SwiftUI into UIKit Apps

Integrating SwiftUI intoUIKit Apps

UPDATED FOR iOS 17!

A detailed guide on gradually adopting SwiftUI in UIKit projects.

  • Discover various ways to add SwiftUI views to existing UIKit projects
  • Use Xcode previews when designing and building UI
  • Update your UIKit apps with new features such as Swift Charts and Lock Screen widgets
  • Migrate larger parts of your apps to SwiftUI while reusing views and controllers built in UIKit