更改UITextField中光标的颜色 [英] Change color of cursor in UITextField

查看:138
本文介绍了更改UITextField中光标的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改UITextField中光标的颜色?

How can I change the color of the cursor in my UITextField?

推荐答案

在iOS 7中,您只需更改UITextFieldtintColor属性即可.这将同时影响文本光标的颜色和文本选择突出显示的颜色.

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中光标的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆