Group Group Group Group Group Group Group Group Group

Button opens a menu like contextMenu (in SwiftUI)

Hallo,

im searching a good way to open a menu with serval entries after tapping a button. I tried .popover, .sheet and many more. But all i get is a sheets, I don’t want the whole screen.
.contextMenu gives me what i want, but i need it at tap on a button, not a longPress. I need just 4 or 5 menu entries to appear after the tap.
Has anyone an idea how to get this? I want to use SwiftUI, if possible.

Thank you and Ciao

Enrico

Hi @rico, I am not sure if there is a work around for using .contextMenu with a single tap. In Apple’s documentation for UIContextMenuInteraction they state that

a context menu interaction object tracks Force Touch gestures on devices that support 3D Touch, and long-press gestures on devices that don’t support it.

Hi, thank you for your answer. Yes, you are right. I realised it as contextMenu and add for the user a small text as hint how to handle it.

1 Like

List {
ForEach(restaurants) { restaurant in
BasicImageRow(restaurant: restaurant)
.contextMenu {

            Button(action: {
                // delete the selected restaurant
            }) {
                HStack {
                    Text("Delete")
                    Image(systemName: "trash")
                }
            }
            
            Button(action: {
                // mark the selected restaurant as favorite
            }) {
                HStack {
                    Text("Favorite")
                    Image(systemName: "star")
                }
            }
        }
}

}