import SwiftUI
struct ContentView: View {
var body: some View {
VStack{
List{
ForEach (0 ..< 10){item in
Text("item .....")
.contextMenu{
Button(action: {
print("add")
}, label: {
Text("add")
})
Button(action: {
print("edit")
}, label: {
Text("edit")
})
}
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
contextMenu 可以使菜单添加到任何视图, 长按就可以显示你编辑的菜单,并且背景会有模糊的效果