且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在文本字段中更改光标的颜色

更新时间:2023-01-23 18:52:17

code> UITextField 的 c> tintColor 属性。这将影响文本光标的颜色和文本选择突出显示颜色。



您可以在代码中执行此操作...

  textField.tintColor = [UIColor redColor]; 

...或在Interface Builder中:





您还可以使用 UITextField 外观代理对您应用程序中的所有文本字段执行此操作:

  [[UITextField appearance] setTintColor:[UIColor redColor]]; 

下面是模拟器屏幕截图,显示了其他普通iOS 7文本字段的外观,其色调设置为红色


$ b



文字选择屏幕截图




How can I change the color of the cursor in my text field?

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];

... or in Interface Builder:

You can also do this for all text fields in your app using the UITextField appearance proxy:

[[UITextField appearance] setTintColor:[UIColor redColor]];

Below are simulator screenshots showing what an otherwise ordinary iOS 7 text field looks like with its tint set to red.

Text cursor screenshot:

Text selection screenshot: