Skip to main content

Ein Kontextmenü mit Aktion

Ein einfache Kontextmenü mit den entsprechenden Buttons und den Aktion dahinter.

import SwiftUI

struct ContentView: View {
    var body: some View {
        Image(systemName: "photo")
            .resizable()
            .frame(width: 100, height: 100)
            .contextMenu {
                Button(action: {
                    // Action for sharing the photo
                }) {
                    Label("Share", systemImage: "square.and.arrow.up")
                }

                Button(action: {
                    // Action for deleting the photo
                }) {
                    Label("Delete", systemImage: "trash")
                }
            }
    }
}