Hide the cursor of an UITextField

后端 未结 13 816
甜味超标
甜味超标 2020-12-07 07:51

I am using a UITextField with a UIPickerView for its inputView, so that when the user taps the text field, a picker is summoned for th

13条回答
  •  無奈伤痛
    2020-12-07 08:41

    You might also want to stop the user from selecting, copying or pasting any text so that the only text input comes from the picker view.

    - (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/

提交回复
热议问题