更改UITextField和UITextView游标/插入颜色 [英] Change UITextField and UITextView Cursor / Caret Color

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

问题描述

我想知道在 UITextField (和 UITextView )中更改光标/插入符的颜色同样的答案)在iOS。

I'm wondering about changing the color of the cursor / caret in a UITextField (And UITextView if its the same answer) in iOS. I've seen answers for OSX development, but nothing for iOS.

这是可能吗?

推荐答案

如果您定位的iOS 7+,这已经变得更容易。只需使用外观代理使用光标更改字段的tintColor,它将应用于整个应用程序:

If you're targeting iOS 7+, this has been made much easier. Simply change the tintColor of the field with a cursor using the appearance proxy and it will apply throughout the app:

Swift 3.0:

Swift 3.0:

UITextField.appearance().tintColor = UIColor.black 


$ b b

Objective-C:

Objective-C:

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

相同的答案适用于单个UITextView:

Same answer applies for an individual UITextView:

Swift 3.0:

Swift 3.0:

UITextView.appearance().tintColor = UIColor.black 

Objective-C

Objective-C

[[UITextView appearance] setTintColor:[UIColor blackColor]];

这篇关于更改UITextField和UITextView游标/插入颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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