How to remove title from actionSheet in SwiftUI

1.3k Views Asked by At

Just like the question asks, how do I remove the title from the action sheet below? I'm using iOS 14, don't want to upgrade to SwiftUI 3. There's no initializer for the actionSheet with a titleVisibility parameter or anything like that. I also tried 'nil' as you can see below, but it's not optional. Not sure how to make the title disappear.

@State var showOptions: Bool = false
Button(action: {
    showOptions = true
}, label: {

}).actionSheet(isPresented: $showOptions) {
ActionSheet(
    title: nil,
    buttons: [
        .cancel(),
        .default(Text("Red")) {
            print("x")
        },

        .default(Text("Green")) {
            print("y")
        },

        .default(Text("Blue")) {
            print("z")
        },
        ]
    )
}
2

There are 2 best solutions below

1
khawar ali On

ConfirmationDialog can be used to show Action Sheet behaviour without title.

struct ContentView: View {
    @State private var showingOptions = false
    @State private var selection = "None"

    var body: some View {
        VStack {
            Text(selection)
            Button("Confirm paint color") {
                showingOptions = true
            }
            .confirmationDialog("", isPresented: $showingOptions, titleVisibility: .automatic) {
                ForEach(["Red", "Green", "Blue"], id: \.self) { color in
                    Button(color) {
                        selection = color
                    }
                }
            }
        }.frame(width:300, height: 600)
    }
}

Result of above code

1
Toseef Khilji On

For iOS 14

You can pass empty ActionSheet title like title: Text("")

enter image description here