问题描述
如何更改UITextField
中光标的颜色?
How can I change the color of the cursor in my UITextField
?
推荐答案
在iOS 7中,您只需更改UITextField
的tintColor
属性即可.这将同时影响文本光标的颜色和文本选择突出显示的颜色.
With iOS 7 you can simply change tintColor
property of the UITextField
. This will affect both the color of the text cursor and the text selection highlight color.
您可以在代码中完成此操作...
You can do this in code ...
textField.tintColor = [UIColor redColor];
...
在Swift 4中:
textField.tintColor = UIColor.red
...或在Interface Builder中:
...or in Interface Builder:
您还可以使用UITextField
外观代理对应用程序中的所有文本字段执行此操作:
You can also do this for all text fields in your app using the UITextField
appearance proxy:
[[UITextField appearance] setTintColor:[UIColor redColor]];
在Swift 4中:
UITextField.appearance().tintColor = UIColor.red
下面是模拟器的屏幕截图,显示了其他普通的iOS 7文本字段,其色调设置为红色.
Below are simulator screenshots showing what an otherwise ordinary iOS 7 text field looks like with its tint set to red.
文本光标屏幕截图:
文本选择屏幕截图:
这篇关于更改UITextField中光标的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!