Reputation: 11
I managed to subclass UITextView and disabled the "Define" contextual menu item.
class TextViewer: UITextView {
// Overide, disable the "Define" contextual menu item
override func canPerformAction(action: Selector, withSender sender: AnyObject?) -> Bool {
if action == "_define:" {
return false;
}
return super.canPerformAction(action, withSender: sender)
}
}
But now, how do I add a different/custom menu item to take its place? I was guessing it might be something like this, but it's not quite right.
var menuController = UIMenuController.sharedMenuController()
var customMenuItem = UIMenuItem(title: "Lookup", action: "lookupWord")
menuController.menuItems?.append(customMenuItem)
Thanks for any help you folks can give me. ;-)
Upvotes: 0
Views: 4443
Reputation: 11
Nevermind:
let mnuController = UIMenuController.sharedMenuController()
let lookupMenu = UIMenuItem(title: "Tshawb", action: "tshawb")
mnuController.menuItems = NSArray(array: [lookupMenu])
// This makes the menu item visible.
mnuController.setMenuVisible(true, animated: true)
Upvotes: 1