Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable blinking cursor in UITextField?

I've followed the instructions here and succesfully set up a UITextField that gets updated with a UIDatePicker. However the cursor in the UITextField is blinking, which seems quite a bit awkward to me.

Is there any solution to get rid of that cursor?

like image 456
Tobias Frischholz Avatar asked Aug 19 '11 14:08

Tobias Frischholz


5 Answers

I realise this is an old question, but with the updates to iOS 7, it is now possible to hide the cursor by doing the following:

[[self textFieldName] setTintColor:[UIColor clearColor]];

It will only work on iOS 7+ however.

like image 121
Jamie Chapman Avatar answered Nov 19 '22 03:11

Jamie Chapman


Subclass UITextfield and Override the - (CGRect)caretRectForPosition:(UITextPosition *)position method and return CGRectZero.

- (CGRect)caretRectForPosition:(UITextPosition *)position {
    return CGRectZero;
}
like image 41
Pradeep Reddy Kypa Avatar answered Nov 19 '22 05:11

Pradeep Reddy Kypa


I hope it will helpful to you.

Set Cursor UIColor -> Empty.

 [[self.textField valueForKey:@"textInputTraits"] setValue:[UIColor clearColor] forKey:@"insertionPointColor"];

In Swift : 2.3

self.textField.valueForKey("textInputTraits")?.setValue(UIColor.clearColor() , forKey:"insertionPointColor")
like image 26
Balaji G Avatar answered Nov 19 '22 05:11

Balaji G


I couldn't get jcm's solution to work. What I ended up doing was to subclass UILabel to mimic a UITextField's interactive functionality without the parts that I didn't want (like the cursor). I wrote a blog post about it here:

http://pietrorea.com/2012/07/how-to-hide-the-cursor-in-a-uitextfield/

Basically, the UILabel subclass needs to overwrite isUserInteractionEnabled, inputView, inputViewAccessory and canBecomeFirstResponder. It's only a few lines of code and it makes more sense.

like image 6
pietrorea Avatar answered Nov 19 '22 05:11

pietrorea


Totally silly hack, but if you set the text field's tint color in the UIView section of the Interface Builder property inspector to match the background color, the cursor will appear invisible:

like image 2
brandonscript Avatar answered Nov 19 '22 04:11

brandonscript