Last active
February 7, 2020 17:51
-
-
Save op183/208d86f213e25c4112bd0884b18878dc to your computer and use it in GitHub Desktop.
context menu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct FullWidthImageView: View { | |
@ObservedObject var model = modelStore | |
var body: some View { | |
VStack { | |
Image(systemName: model.img) | |
.resizable() | |
.aspectRatio(contentMode: .fit) | |
.frame(width: 200) | |
Text(model.img) | |
}.contextMenu(ContextMenu() { | |
Button(action: { | |
self.model.toggle.toggle() | |
}) { | |
HStack { | |
Text("toggle image to?") | |
Image(systemName: model.img2) | |
} | |
} | |
Button("No") {} | |
}) | |
} | |
} | |
class Model:ObservableObject { | |
@Published var toggle = false | |
var img: String { | |
toggle ? "pencil.and.outline": "trash" | |
} | |
var img2: String { | |
toggle ? "trash" : "pencil.and.outline" | |
} | |
} | |
let modelStore = Model() | |
struct ContentView: View { | |
var body: some View { | |
VStack { | |
FullWidthImageView() | |
Text("Long press the image to change it").bold() | |
} | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment