Disable text selection UITextView

前端 未结 3 2013
攒了一身酷
攒了一身酷 2021-01-17 01:48

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

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {   
           


        
相关标签:
3条回答
  • 2021-01-17 02:37
    textView.editable = NO;
    

    or

    [textView setEnabled:NO];
    

    im not sure what u meant

    0 讨论(0)
  • 2021-01-17 02:41

    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)];
    }
    
    0 讨论(0)
  • 2021-01-17 02:47

    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;
    }
    
    0 讨论(0)
提交回复
热议问题