Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove "Copy" option from "share" within the UIMenuController on IOS9?

I have a UITextView in which i load some text. Before IOS 9, i did remove the "copy" option while you select a text inside that textview. I did so by subclassing it and doing the following :

@implementation myCustomClass


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

     return [super canPerformAction:action withSender:sender];
}

This was enough to remove the option "Copy". But now in IOS 9, when you select a text, a Share button appears, and if you click it, a new menu appears including the option to copy. How can i disable the copy option, or even disable the "Share" button ?

like image 277
Elias Rahme Avatar asked Oct 05 '15 07:10

Elias Rahme


1 Answers

Try this out:

#import "MyTextView.h"

@implementation MyTextView


- (BOOL)canPerformAction:(SEL)iAction withSender:(id)iSender {
    SEL shareSelector = NSSelectorFromString(@"_share:");

    if (iAction == shareSelector) {
        return NO;
    }

    if (iAction == @selector(copy:)) {
        return NO;
    }

    return [super canPerformAction:iAction withSender:iSender];
}
like image 58
Abhinav Avatar answered Sep 28 '22 12:09

Abhinav