14

I want to disable copy/paste menu and i'm using HTML tag in UITextView in which multiple hyperlinks and want to only disable menu.

My texview image

enter image description here

Satheesh
  • 10,642
  • 6
  • 49
  • 91
Umer Afzal
  • 341
  • 1
  • 2
  • 16
  • i use this code in subclass that can't press links in textview and not showing copy/paste menu. - (BOOL)canBecomeFirstResponder { return NO; } then i write this code then allow to press links but in other text show "Define" - (BOOL)canPerformAction:(SEL)action withSender:(id)sender { if (action == @selector(selectAll:) && action == @selector(select:) && action == @selector(cut:) && action == @selector(copy:) && action == @selector(paste:)) return NO; return [super canPerformAction:action withSender:sender]; } plz help me in this case. – Umer Afzal Feb 24 '14 at 04:27
  • I exactly want as above question. U were found any solution for that ?? – Monika Patel Jan 15 '16 at 04:00

3 Answers3

13

just try to create a subclass of UITextView that overrides the canPerformAction:withSender: method

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    if (action == @selector(paste:))
        return NO;
    return [super canPerformAction:action withSender:sender];
}
gunas
  • 1,849
  • 1
  • 15
  • 28
11

You can play with this property:

enter image description here

and this one :

enter image description here

Nicolas Bonnet
  • 1,275
  • 11
  • 14
8

You need to create a subclass of UITextView and override the canPerformAction method.

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    if (action == @selector(copy:) || action == @selector(selectAll:) || action == @selector(paste:))
        return NO;
    return [super canPerformAction:action withSender:sender];
}
Sujith Thankachan
  • 3,490
  • 2
  • 19
  • 25
  • In order to do this, you need to subclass your UITextView and put this method. override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool { if (action == #selector(copy(_:))) { return false } if (action == #selector(cut(_:))) { return false } if (action == #selector(paste(_:))) { return false } return super.canPerformAction(action, withSender: sender) } – Zaldy Bughaw May 25 '17 at 11:58