Nikunj
Nikunj

Reputation: 987

UITextview Hide cursor/Change color of cursor

In my application, In UITextview i want to hide cursor.

If this is not possible then I want to change color of cursor.

Can we do this? I have search for it but only getting answers for UITextfield.

Thanks.

Upvotes: 4

Views: 5097

Answers (3)

matm
matm

Reputation: 7079

To hide the cursor, just subclass UITextField and override -caretRectForPosition: which is implemented by UITextField to conform with UITextInput protocol:

- (CGRect)caretRectForPosition:(UITextPosition *)position
{
    return CGRectZero;    // ensures the cursor won't appear
}

As for changing the color or the cursor, I think it's not possible without accessing private API.

EDIT: as per S. Soffes comment, changing the color is possible via tintColor property, obviously.

Upvotes: 2

hankbao
hankbao

Reputation: 340

On iOS 7, you can simply set the tintColor of your text view as the same of its backgroundColor to make the cursor invisible.

textView.tintColor = textView.backgroundColor;

or you can try:

textView.tintColor = [UIColor clearColor];

Upvotes: 13

Shanmu G
Shanmu G

Reputation: 120

You can hide the cursor only if you disabled the editing property set to No

Upvotes: 3

Related Questions