I would like to open bottom sheet with custom option and not medium or large detents.I checked in SwiftUI there is API called .fraction but couldn’t find similar API in UIKit.
SwiftUI
Text("Detail")
.presentationDetents([.fraction(0.1)])
UIKit
if let sheet = viewControllerToPresent.sheetPresentationController {
sheet.detents = [.medium()]
2
Answers
Thanks I also found one more way to do this.
I inspected the underlying
UISheetPresentationController
of a SwiftUIsheet
on iOS 17.4, and saw that the detents have a type of "custom".This suggests that
.fraction(...)
and.height(...)
in SwiftUI simply creates UIKit detents using the.custom
factory method. On the other hand,.medium
and.large
in SwiftUI does correspond to.medium()
and.large()
in UIKit.Here is an extension on
UISheetPresentationController.Detent
that adds afraction
factory method: