我正在尝试根据用户的偏好设置 UITextView 的光标颜色。他们用一个按钮选择他们想要的颜色。
默认情况下, TextView 的光标颜色为白色。当用户按下按钮时,它可能会变为绿色:
[_textView setTintColor:[UIColor greenColor]];
[_textView setTextColor:[UIColor greenColor]];
我确信这个方法调用是有效的,因为 TextView 的文本改变了颜色,而不是光标...
最佳答案
我能够重现您的行为:如果我在未选择 TextView (又名:不是第一响应者)时更改色调和文本颜色,一切都会按预期工作。
但如果我首先选择它,通过点击它而不是通过按下按钮更改颜色,它们的插入符号(色调)颜色不会改变。
解决方法如下:
- (IBAction)changeColor:(id)sender
{
[_textView setTextColor:[UIColor greenColor]];
[_textView setTintColor:[UIColor greenColor]];
if([_textView isFirstResponder]){
[_textView resignFirstResponder];
[_textView becomeFirstResponder];
}
}
关于ios - UITextView 光标颜色不改变 iOS 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23725552/