Change UITextField and UITextView Cursor / Caret Color

RileyE picture RileyE · Jul 23, 2012 · Viewed 120.1k times · Source

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.

Is this even possible?

Answer

DiscDev picture DiscDev · Sep 22, 2013

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:

UITextField.appearance().tintColor = .black 

Objective-C:

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

Same answer applies for an individual UITextField:

Swift 3.0:

myTextField.tintColor = .black 

Objective-C

[myTextField setTintColor:[UIColor blackColor]];