9th October 2014

Disabling the caret and text entry in UITextFields

Guides | Tutorial By 2 years ago

If you set the UITextField inputView to a UIPickerView, UIDatePicker or custom view, you may want to disable the caret in the UITextField.

You will probably also want to stop the user from entering in any text or copying, selecting or pasting any text into the UITextField. This way the only input into the UITextField is from the inputView.

To achieve this, add the following code the the UITextField subclass.

- (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:))

    return [super canPerformAction:action withSender:sender];

Recommended Posts

Yammer integrations in ReactJS

Post by 2 years ago

I am writing this blog while I am working on a project for our client’s intranet website. The client requires the website has the ability to share, like and write comments in the website through

Got an idea?

We help entrepreneurs, organizations and established brands from around
the country bring ideas to life. We would love to hear from you!