article

Friday, May 7, 2021

SwiftUI How to show a menu when a button is pressed

SwiftUI How to show a menu when a button is pressed
 
//
//  ContentView.swift
//  Testapp
//
//  Created by Cairocoders
//

import SwiftUI

struct ContentView: View {
    var body: some View {
        Menu("Options") {
            Button("Order Now", action: placeorder)
            Button("Adjust Oder", action: adjustorder)
            Menu("Advanced") {
                Button("Rename", action: rename)
                Button("Delay", action: delay)
            }
            Button("Cancel", action: canceloder)
        }
    }
    
    func placeorder() {
        print("Order succesfully")
    }
    func adjustorder() {
        print("Order Adjusted")
    }
    func canceloder() {
        print("Order Cancel")
    }
    func rename() {
        print("Order Rename")
    }
    func delay() {
        print("Delay order")
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Related Post