What I Whant
I'm making a component. This component is used to display a list of tags. I want a context menu to pop up on the tag when the user long-presses it. Like this:
What I Got
Here is My Code
VStack(alignment: .leading) {
ForEach(groupedItems, id: \.self) { itms in
HStack {
ForEach(itms, id: \.self) { tag in
Text(tag.title ?? "")
.font(.callout)
.padding()
.frame(height: 24.0)
.frame(alignment: .center)
.cornerRadius(100)
.contextMenu {
Button {
deleteTheTag(tag)
} label: {
Label("Delete", systemImage: "trash")
}
}
}
}
}
}
I tried several methods, but all failed. How should I modify my code?