I need to add UIMenu (dropdown) to a custom UIView and there is no such option. I have this option on buttons but I really need it on a view.
func createMenu() -> UIMenu{
let destruct = UIAction(title: "Destruct", attributes: .destructive) { _ in }
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: { _ in })
])
return items
}
The target is iOS 14 so there is no backwards compatibility issue.