I am developing an application with SwiftUI where i would like to insert an option in the menu that appears when text is selected, it was a custom item for this menu.
I want to know if it was possible to make this feature. thanks
You need to use canPerformAction
for example if you only want to keep "copy", "Select all" and add the "comment" button
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool { let menu = UIMenuController.shared let newInstanceItem = UIMenuItem(title: "Comment", action:#selector(reportAFault)) menu.menuItems = [newInstanceItem] menu.update() if action == #selector(copy(_:)) || action == #selector(selectAll(_:)) || action == #selector(commentThisText){ return true } return false } @objc func commentThisText() { YOUR CODE }
You need to use canPerformAction
for example if you only want to keep "copy", "Select all" and add the "comment" button