Ein Kontextmenü mit Vorschau
In diesem Beispiel wird gezeigt, wie ein Kontextmenü mit Vorschau erstellt wird.
import SwiftUI
struct ContentView: View {
var body: some View {
Image(systemName: "star.fill")
.resizable()
.frame(width: 100, height: 100)
.contextMenu {
Button("Favorite") {
print("Favorited")
}
} preview: {
Text("This is a star icon")
.padding()
.background(Color.yellow)
.cornerRadius(10)
}
}
}