0

I want to disable text selection on a UITextView. Until now what i've already done is:

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender { [UIMenuController sharedMenuController].menuVisible = NO; if (action == @selector(paste:)) return NO; if (action == @selector(select:)) return NO; if (action == @selector(selectAll:)) return NO; return NO; } 

In this away I set UIMenuController to hidden and i put a stop to text copy but the text selection is still visible.

Google results (also StackOverflow) take me to no solution. Has someone already faced the same problem? Any ideas?

3 Answers 3

3

If you want to prevent the text selection but keep links interactions, add the following textview delegate methods

- (void)textViewDidChangeSelection:(UITextView *)textView { [textView setSelectedRange:NSMakeRange(NSNotFound, 0)]; } 
Sign up to request clarification or add additional context in comments.

1 Comment

This will crash the application if theres any attempt to backspace.
2

If you want to disable cut/copy/paste on all UITextView of your application you can use a category with :

@implementation UITextView (DisableCopyPaste) - (BOOL)canBecomeFirstResponder { return NO; } @end 

It saves a subclassing... :-)

Otherwise, just subclass UITextViewand put :

- (BOOL)canBecomeFirstResponder { return NO; } 

2 Comments

The question is about disabling text selection on a UITextView and this is what this piece of code does...
This will also disable text input though surely? Yeah, just tested. This disables any text input to the text field.
-1
textView.editable = NO; 

or

[textView setEnabled:NO]; 

im not sure what u meant

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.