I want to add an UIMenu to my application, I was practicing with it and now have the question if is possible to set the location of the UIMenu
a little higher than the button is currently displaying it:
as you can see in this photo the menu currently overlay the tab bar and I wanted to set it a little higher than than the tab bar. here is my code:
let menu = UIMenu(title: "", children: [
UIAction(title: NSLocalizedString("Gallery", comment: ""), image: UIImage(systemName: "folder"), handler: {
(_) in
self.loadPhotoGallery()
})
])
btnMenuExtras.menu = menu
iOS 14+
Sinse iOS 14
UIControl
has method that provides point to which attach a menuso you can override
UIButton
to provide desired location for a menu (calculated or hardcoded) relatively to the button itself (`cause it is in button's coordinate space) and use that button either in storyboard (as a class for control) or created programmatically (if you need to inject it somewhere):Result:
Demo prepared & tested with Xcode 13 / iOS 15