Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created February 13, 2021 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sturdysturge/90a0656631efdb2e39c647a9deb74244 to your computer and use it in GitHub Desktop.
Save sturdysturge/90a0656631efdb2e39c647a9deb74244 to your computer and use it in GitHub Desktop.
import SwiftUI
struct ContentView: View {
@State var selectedIndex = -1
var selection: String {
switch selectedIndex {
case 0: return "\u{2664}"
case 1: return "\u{2663}"
case 2: return "\u{2660}"
case 3: return "\u{2666}"
default: return ""
}
}
var body: some View {
VStack {
Text("Favourite card suit:")
Text(selection)
.font(.system(size: 200))
.focusable()
.padding()
.contextMenu {
Button("\u{2664} - Hearts") {selectedIndex = 0}
Button("\u{2663} - Clubs") {selectedIndex = 1}
Button("\u{2660} - Spades") {selectedIndex = 2}
Button("\u{2666} - Diamonds") {selectedIndex = 3}
}
Text("Long press to make a choice")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment