Please tell me how to customize this menu? Perhaps another way to do it?
let barMenu = UIMenu(title: "", children: [
UIAction(title: NSLocalizedString("menu_item_home", comment: "")){
action in
print("menu_item_home 1")
},
UIAction(title: NSLocalizedString("menu_item_settings", comment: "")){
action in
print("menu_item_settings 2")
let settingsStoryboard = UIStoryboard(name: "Settings", bundle: nil)
let settingsController = settingsStoryboard.instantiateViewController(withIdentifier: "SettingsScene") as! SettingsViewController
controller.navigationController?.pushViewController(settingsController, animated: true)
},
UIAction(title: NSLocalizedString("menu_item_contacts", comment: "")){
action in
print("menu_item_contacts 3")
},
])
let navBarMenu = UIBarButtonItem(image: UIImage(systemName: "text.justify"), menu: barMenu)
navigationItem.rightBarButtonItem = navBarMenu
I need to add a menu to a NavigationBar and customize its appearance. Point in the right direction please
Unfortunately
UIMenu
is not anUIView
and there are very little options to customize it. There is no way to change the background or text color at least not in current iOS 15 and at least without doing some stupid workarounds. If you need to have a different appearance in this menu then perhaps you can create something similar with a custom popover instead of using UIMenu. That would give you much more customization options. Not exactly what you asked for but maybe it will fit your needs. Possible implementation of a similar menu based on a popover could look more or less like below:And then present it somewhere from your code like this: