Reputation: 9054
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...
Upvotes: 11
Views: 8459
Reputation: 4739
I'm using small hack in UITextViewDelegate method:
func textViewDidBeginEditing(_ textView: UITextView) {
let color = textView.tintColor
textView.tintColor = .clear
textView.tintColor = color
}
UPD
more technological way:
1) implement method in extension:
extension UITextView {
func resetTintColor(){
let color = tintColor
tintColor = .clear
tintColor = color
}
}
2) in an UITextViewDelegate implementation:
func textViewDidBeginEditing(_ textView: UITextView) {
textView.resetTintColor()
}
Upvotes: 6
Reputation: 3878
You can use
[_textView reloadInputViews];
And in Swift
textView. reloadInputViews()
Then you won't need to handle keyboard incoming and going.
Upvotes: 2
Reputation: 52227
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];
}
}
Upvotes: 22