I\'m having a hard time getting the UITextView
to disable the selecting of the text.
I\'ve tried:
canCancelContentTouches = YES;
It sounds like what you actually want is a giant UILabel inside a UIScrollView, and not a UITextView.
update: if you are on newer versions of iOS UILabel now has a lines property:
Multiple lines of text in UILabel
Did you try setting userInteractionEnabled to NO for your UITextView? But you'd lose scrolling too.
If you need scrolling, which is probably why you used a UITextView and not a UILabel, then you need to do more work. You'll probably have to override canPerformAction:withSender:
to return NO
for actions that you don't want to allow:
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
switch (action) {
case @selector(paste:):
case @selector(copy:):
case @selector(cut:):
case @selector(cut:):
case @selector(select:):
case @selector(selectAll:):
return NO;
}
return [super canPerformAction:action withSender:sender];
}
For more, UIResponderStandardEditActions .
For swift, there is a property called "isSelectable" and its by default assign to true
you can use it as follow:
textView.isSelectable = false
Swift 4, Xcode 10
This solution will
Make sure you set the delegate to YourViewController
yourTextView.delegate = yourViewControllerInstance
Then
extension YourViewController: UITextViewDelegate {
func textViewDidChangeSelection(_ textView: UITextView) {
view.endEditing(true)
}
}
If you just want to prevent it from being edited, then set the UITextView's "editable" property to NO/False.
If you're trying to leave it editable but not selectable, that's going to be tricky. You might need to create a hidden textview that the user can type into and then have UITextView observe that hidden textview and populate itself with the textview's text.
Swift 4, Xcode 10:
If you want to make it so the user isn't able to select or edit the text.
This makes it so it can not be edited:
textView.isEditable = false
This disables all user interaction:
textView.isUserInteractionEnabled = false
This makes it so that you can't select it. Meaning it will not show the edit or paste options. I think this is what you are looking for.
textView.isSelectable = false