UIButton and Temporary UIMenu

612 Views Asked by At

Can you change whether a UIButton has a UIMenu or not depending on external conditions?

let infoButton = UIButton()
infoButton.showsMenuAsPrimaryAction = true
infoButton.menu = UIMenu(options: .displayInline, children: [])
infoButton.addAction(UIAction { [weak infoButton] (action) in
   infoButton?.menu = infoButton?.menu?.replacingChildren([new items go here...])
}, for: .menuActionTriggered)

Is there a way to block that menu, but trigger a TouchUpInside type of a control event on certain conditions?

1

There are 1 best solutions below

0
matt On

If you didn’t want the menu to appear when the button is tapped, you should not have set showsMenuAsPrimaryAction to true. That value means that the touch up inside target-action, if there is one, is ignored and the menu appears instead.