skip to Main Content

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

Answers


  1. 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

    Login or Signup to reply.
  2. For iOS 14

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

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search