Prevent editing of text in UITextField and hide cursor/caret/magnifying glass while using an inputView

后端 未结 6 1636
北荒
北荒 2021-02-13 01:40

How do I prevent the editing of text in a UITextField along with hiding the cursor/caret/magnifying glass, but still present the keyboard, as I am using an in

6条回答
  •  一整个雨季
    2021-02-13 02:30

    I found the best solution was

    - (CGRect) caretRectForPosition:(UITextPosition*) position
    {
        return CGRectZero;
    }
    
    - (NSArray *)selectionRectsForRange:(UITextRange *)range
    {
        return nil;
    }
    
    - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
    {
        if (action == @selector(copy:) || action == @selector(selectAll:) || action == @selector(paste:))
        {
            returnNO;
        }
    
        return [super canPerformAction:action withSender:sender];
    }
    

    http://b2cloud.com.au/tutorial/disabling-the-caret-and-text-entry-in-uitextfields/

提交回复
热议问题