
MenuWithAView is a SwiftUI package that lets you add accessory views to your context menu interactions, with UIKit's private _UIContextMenuAccessoryView.
Compatible with iOS 18 and later
contextMenuAccessory
is a SwiftUI modifier that lets you attach an accessory view to a .contextMenu
. You can control the accessory’s placement, location, alignment, and tracking axis.
DocC documentation is available for this modifier.
placement
: Where the accessory is attached relative to the context menu.
(Default:.center
)location
: The location where the accessory appears.
(Default:.preview
)alignment
: How the accessory aligns within its container.
(Default:.leading
)trackingAxis
: The axis along which the accessory tracks user interaction.
(Default:[.xAxis, .yAxis]
)accessory
: The view to display as the accessory.
Text("Turtle Rock")
.padding()
.contextMenu {
Button(action: {}) {
Label("Button", systemImage: "circle")
}
}
.contextMenuAccessory(
placement: .center,
location: .preview,
alignment: .leading,
trackingAxis: .yAxis
) {
Text("Accessory View")
.font(.title2)
.padding(8)
.background(Color.blue.opacity(0.6))
.clipShape(RoundedRectangle(cornerRadius: 12))
.padding(16)
}
Special thanks to @sebjvidal for writing about _UIContextMenuAccessoryView, and helping with the development of this package!
This project is released under the MIT License. See LICENSE for details.
Contributions are welcome! Please feel free to submit a Pull Request. Before you begin, take a moment to review the Contributing Guide for details on issue reporting, coding standards, and the PR process.
If you like this project, please consider giving it a ⭐️
Aether | Seb | |
---|---|---|
@AetherAurelia | @SebJVidal | |
Threads | @aetheraurelia | - |
Bluesky | aethers.world | - |
aether | - | |
GitHub | here, obviously | here!! |
Website | - | sebvidal.com |
Built with 🍏🕵️🤝👜 by Aether and Seb