Gavin Wiggins

AboutNotesPhotos


Toolbar dropdown

Written on November 13, 2022

Place a menu in a toolbar item to display a dropdown when the toolbar item is clicked.

toolbar dropdown

import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack {
            Text("Click the toolbar item to see a dropdown menu.")
        }
        .toolbar {
            ToolbarItem {
                Menu {
                    Button("Open in Preview", action: {})
                    Button("Save as PDF", action: {})
                } label: {
                    Label("Star", systemImage: "star.fill")
                }
            }
        }
        .frame(width: 400, height: 300)
    }
}

Gavin Wiggins © 2024.
Made on a Mac with Genja. Hosted on GitHub Pages.