5

On UITextField long tap, there are some options now, i.e., 'replace...' and 'share...' in addition to 'cut', 'copy', 'paste' and 'define' options. It is possible to disable these 'cut', 'copy', 'paste' and 'define' options via 'canPerformAction:withSender' method, but I could not find a way to disable these 'replace...' and 'share...' options. Are there any selector available for this also or could this be disabled any other way ? Anybody has come across this and successfully disabled these options? please suggest.

XiOS
  • 1,665
  • 2
  • 18
  • 22

2 Answers2

0

You can intercept long press event and give you own implementation and required behaviour. Please check accepted answer:
How to intercept long press on UITextView without disabling context menu?
or provide allowed actions

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    if (action == @selector(copy:) ||
        action == @selector(selectAll:)) {
        return true;
    }

    return false;
}

For more details: How to disable copy paste option from UITextField programmatically

Community
  • 1
  • 1
Aamir
  • 16,329
  • 10
  • 59
  • 65
  • 2
    Hi, thanks for your reply, but as I mentioned in the question I knew that is the way to disable 'cut', 'copy', 'paste', 'select', 'select all' options, but I would want to disable the 'Replace' and 'Share' options which I was not able to achieve via 'canPerformAction:withSender' method. – XiOS Jun 20 '16 at 05:21
0

Late to the party, but one option could be to use the action's description. Apple hasn't exposed Share as one of the UIResponderStandardEditActions items. So the workaround for this is to use action's description. Not an elegant solution, but should do the trick:

override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
        if action == #selector(UIResponderStandardEditActions.copy(_:)) ||
           action.description.contains("_share") { // disabling share
               return false
        } else {
               return super.canPerformAction(action, withSender: sender)
        }
}
iHS
  • 5,372
  • 4
  • 31
  • 49