Apollo Apollo - 1 month ago 22
iOS Question

UITextView Cursor Color not changing iOS 7

I'm trying to set the cursor color of a UITextView based on a user's preferences. They select what color they want with a button.

By default, the textview's cursor color is white. When the user presses the button, it might change to green:

[_textView setTintColor:[UIColor greenColor]];
[_textView setTextColor:[UIColor greenColor]];


I am sure that this method call is working because the textview's text changes color, just not the cursor...

Answer

I was able to recreate your behavior: If I change the tint and text color while the text view isn't selected (aka: not first responder), everything will work as expected.

But if I first select it, by tapping it and than change the color by button press, they caret's (tint) color won't change.

Here is a workaround:

- (IBAction)changeColor:(id)sender 
{
    [_textView setTextColor:[UIColor greenColor]];
    [_textView setTintColor:[UIColor greenColor]];

    if([_textView isFirstResponder]){
        [_textView resignFirstResponder];
        [_textView becomeFirstResponder];
    }
}