I couldn't find any solution.
I couldn't find any solution.
Open a UIMenu when you tap the button ?
Have a UIMenu inside the UIButton ?
Code Block let destruct = UIAction(title: "Destruct", attributes: .destructive) { _ in } 2 let items = UIMenu(title: "More", options: .displayInline, children: [ UIAction(title: "Item 1", image: UIImage(systemName: "mic"), handler: { _ in }), UIAction(title: "Item 2", image: UIImage(systemName: "envelope"), handler: { _ in }) UIAction(title: "Item 3", image: UIImage(systemName: "flame.fill"), handler: { _ in UIAction(title: "Item 4", image: UIImage(systemName: "video"), state: .on, handler: ]) button.menu = UIMenu(title: "", children: [items, destruct])
I have the same question
In iOS 16 (and possibly prior), you can use UIAlertController with preferredStyle set to .actionSheet. Create a UIAlertAction for each option and add each action to the UIAlertController object. Then you can present the UIAlertController like you might with any other view controller with UIViewController.present(...)
As per the example below you can cause the selection action to call back to the object that configures the alert to notify of the selection.
let option1 = UIAlertAction(title: "Option 1", style: .default) { [weak self] _ in
self?.handleOptionSelection("Option 1")
}
Although UIAlertController is a subclass of UIViewController, there are limitations about what you can do if you use that class however, as Apple says it's not designed for subclassing nor are its private methods intended to be used by apps. If you need to customize the appearance quite a bit, you may have to do some more leg work and use a custom view controller for the pop-up content and a UIPresentationController to handle the presentation and dismissal.
Did anyone ever find a solution for this? I'd like to present a UIMenu from a UIView as a result of a gesture recognizer firing... is that possible?