Search code examples
swiftuiswiftui-sheet

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


Solution

  • I don't think there's one accepted name for it; I usually call it a drag handle as it's there to indicate a draggable area to users.

    There is no built-in syntax to add one to a sheet. That's the benefit of SwiftUI – simple controls are easy to implement and customize.

    For completeness, you can make one using something like the following:

    VStack {
        Capsule()
            .fill(Color.secondary)
            .frame(width: 30, height: 3)
            .padding(10)
    
        // your sheet content here
    
        Spacer()
    }