Reputation: 3202
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?
Upvotes: -1
Views: 649
Reputation: 535989
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.
Upvotes: 1