ActionMenu is a SwiftUI library that provides a flexible and easy-to-use menu component for iOS applications, similar to the one in Apple's built-in mail app.
- iOS 18.0+
- Swift 6.0+
- In Xcode, open your project and navigate to File > Add Packages...
- In the search field, enter the package repository URL:
https://github.com/peterfriese/ActionMenu - Select the package when it appears in the search results
- Choose your target application in the "Add to Project" field
- Click "Add Package"
Add the following dependency to your Package.swift file:
dependencies: [
.package(url: "https://github.com/peterfriese/ActionMenu", from: "1.0.0")
]Then, include "ActionMenu" as a dependency for your target:
targets: [
.target(
name: "YourTarget",
dependencies: ["ActionMenu"])
]- Import the package in your SwiftUI file:
import SwiftUI
import ActionMenu- Use the
.actionMenumodifier on any view:
.actionMenu(title: "Actions", isPresented: $isShowingMenu) {
Button("Option 1") {
// Handle option 1
}
Button("Option 2") {
// Handle option 2
}
}Here's a complete example showing how to use ActionMenu with a list:
struct ContentView: View {
@State private var isMoreActionTapped = false
@State private var selectedItem: String? = nil
var body: some View {
List(items, id: \.self) { item in
Text(item)
.swipeActions {
Button("More", systemImage: "ellipsis.circle") {
selectedItem = item
isMoreActionTapped.toggle()
}
}
}
.actionMenu(title: "Actions", isPresented: $isMoreActionTapped) {
Button("Flag", systemImage: "flag") {
// Handle edit action
}
Button("Delete", role: .destructive) {
// Handle delete action
}
}
}
}The ActionMenu can be styled using standard SwiftUI techniques. The default appearance is designed to mimic the look and feel of the menu in Apple's Mail app.
To ensure the menu looks "at home" on different iOS versions, ActionMenu uses a backporting pattern for some of its styles. For example, the toolbar button on the sheet will use the .glassProminent button style on iOS 26 and newer, while falling back to a standard button style on older versions.
Contributions are welcome! Please feel free to submit a PR.
ActionMenu is licensed under the Apache 2 license. See the LICENSE file for details.
Peter Friese
