Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI: How to add a gray line bar on Sheet?

I know how to add this element with HStack and Rectangle. But...

  1. How is it called?

  2. Does SwiftUI have this element out of the box?

Unknown element

like image 702
Tim Avatar asked Sep 13 '25 08:09

Tim


2 Answers

iOS16:

It is added automatically if you have more than one detent, so for just one detent you will have to be explicit about the visibility:

yourContentView
    .presentationDetents([.medium])
    .presentationDragIndicator(.visible)
like image 191
Hans Terje Bakke Avatar answered Sep 16 '25 18:09

Hans Terje Bakke


  1. The thing is called a Drag Indicator.
  2. With iOS 16+ you can use .presentationDragIndicator(_:) modifier to control its visibility.

Proposals have been made on how to emulate this drag indicator in earlier iOS versions.

As a small addition to the great answers of John M. and happymacaron, this comes even closer:

ZStack(alignment: .top) {
    // NavigationView
    Capsule()
        .fill(Color.secondary)
        .opacity(0.5)
        .frame(width: 35, height: 5)
        .padding(6)
}
like image 45
soundflix Avatar answered Sep 16 '25 16:09

soundflix



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!