I have a UITextField that displays only numeric values (0-9, ., -). When a user selects the contents of the text field, a menu with "copy","paste" and "define" appears. Since the textfield only displays numerical values, I don't want the "define" option to appear. How do I disable the dictionary "define" option in a UITextField?
Edit: I've solved this and posted the solution below
Swift - iOS 8
You can do it by subclassing UITextField and overriding canPerformAction:WithSender method.
class MyTextFieldWithoutDefine: UITextField {
    override func canPerformAction(action: Selector, withSender sender: AnyObject?) -> Bool {
        if action == "_define:" {
            return false
        }
        return super.canPerformAction(action, withSender: sender)
    }
}
List of all actions:
cut:
copy:
select:
selectAll:
paste:
delete:
_promptForReplace:
_transliterateChinese:
_showTextStyleOptions:
_define:
_addShortcut:
_accessibilitySpeak:
_accessibilitySpeakLanguageSelection:
_accessibilityPauseSpeaking:
makeTextWritingDirectionRightToLeft:
makeTextWritingDirectionLeftToRight:
                        the solution in the question comment area did not work for me (ios8), i got error with:
action == @selector(defineSelection:)
i was able to remove 'define' from edit menu by specifing the options i wanted to include in the menu:
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    if (action == @selector(copy:) ||
        action == @selector(selectAll:)) {
        return true;
    }
    return false;
}
more complete answer at: How to disable copy paste option from UITextField programmatically (thank you serge-k)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With