How to disable Copy , Paste, selectAll, select etc… action for UITextView

H

Its very simple 🙂 🙂

Step 1:
Create SubClass file with name CustomUITextView for UITextView

In .m file write below code

– (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(selectAll:) || action == @selector(select:) ||action == @selector(copy:) || action == @selector(paste:))
{
return NO;
}

return NO;
}

Step 2: Add below code

translationLable = [[CustomUITextView alloc] initWithFrame:CGRectMake(15, 50, 240, 245 + 38)];
translationLable.text = @”wordString”;
translationLable.delegate = self;
//translationLable.numberOfLines = 20;
translationLable.backgroundColor = [UIColor clearColor];
//[translationLable sizeToFit]; //R-60, G-66, B-70
translationLable.textColor = [UIColor colorWithRed:60.0/255.0 green:66.0/255.0 blue:70.0/255.0 alpha:1.0];
translationLable.editable = FALSE;
translationLable.font = [UIFont fontWithName:@”MyriadPro-Light” size:18.0];
translationLable.dataDetectorTypes = UIDataDetectorTypeLink;
[self.view addSubview:translationLable];

About the author

mayur.bhansali
By mayur.bhansali

Category