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 f
It is only possible by accessing a private property and therefore may cause an Apple AppStore app rejection.
take a look at this Stackoverflow question
Setting tintColor
for UITextField
and UITextView
works differently.
While for UITextField
you don't need to call additional code after updating tintColor
to change cursor color, but for UITextView
you need.
So after setting tintColor
for UITextView
(it doesn't matter in IB or in code) you need to call textView.tintColorDidChange()
in order to apply it (actually it will pass text view's config down to its subviews hierarchy).
A more general approach would be to set the UIView's appearance's tintColor.
UIColor *myColor = [UIColor purpleColor];
[[UIView appearance] setTintColor:myColor];
Makes sense if you're using many default UI elements.
If the UITextField
is from UISearchBar
then first get the textField
from searchBar
and then apply tintColor
property:
let textFieldInsideSearchBar = searchBar.value(forKey: "searchField") as? UITextField
textFieldInsideSearchBar?.tintColor = UIColor.lightGray