Last active
July 20, 2019 11:53
-
-
Save laevandus/3e2443710bd49248eeffdc2cb3afc6ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension ViewController: UIContextMenuInteractionDelegate { | |
func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? { | |
let actionProvider: ([UIMenuElement]) -> UIMenu? = { _ in // menu elements from responder chain if any | |
// Creating actions… | |
let imageAction = UIAction(title: "Title (image)", | |
image: UIImage(systemName: "arkit"), | |
identifier: nil, | |
discoverabilityTitle: nil, | |
attributes: [], | |
state: .off, | |
handler: actionHandler) | |
let destructiveAction = UIAction(title: "Title (destructive)", | |
image: nil, | |
identifier: nil, | |
discoverabilityTitle: nil, | |
attributes: .destructive, | |
state: .off, | |
handler: actionHandler) | |
let submenu = UIMenu(title: "Submenu", | |
image: nil, | |
identifier: nil, | |
options: [], | |
children: [destructiveAction, disabledAction]) | |
return UIMenu(title: "Optional Menu Title", | |
image: nil, | |
identifier: nil, | |
options: [], | |
children: [titleAction, imageAction, onDiscoverabilityTitleAction, submenu]) | |
} | |
return UIContextMenuConfiguration(identifier: "my identifier" as NSCopying, | |
previewProvider: nil, | |
actionProvider: actionProvider) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment