Learning Time : 1h 40min
My Github : Hot Prospects Source Code
Context menus provide users with additional functionality when they press and hold on a view, similar to 3D Touch on older iPhones.
contextMenu(menuItems:) | Apple Developer Documentation
struct ContentView: View {
@State private var backgroundColor = Color.red
var body: some View {
VStack {
Text("Hello, World!")
.padding()
.background(backgroundColor)
Text("Change Color")
.padding()
.contextMenu {
Button("Red") {
backgroundColor = .red
}
Button("Green") {
backgroundColor = .green
}
Button("Blue") {
backgroundColor = .blue
}
}
}
}
}