UITextView disabling text selection

后端 未结 11 1091
误落风尘
误落风尘 2020-12-08 00:19

I\'m having a hard time getting the UITextView to disable the selecting of the text.

I\'ve tried:

canCancelContentTouches = YES;
         


        
11条回答
  •  太阳男子
    2020-12-08 00:52

    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 .

提交回复
热议问题