How can I programmatically change the color of the prompt on mac catalyst for an UITextField?
The prompt exist but with the same color as UITextField.
The prompt is showing the right color on iOS.
I unsuccessfully tried .tintColor
Code + iOS and Mac Catalyst result
After a lot of searching around, I think I've found a workaround for this. You can use the key-value coding paradigms to get at the insertionPointColor property (which is what you ultimately need to set). Here is an example of setting the caret color to red. Be careful to only do this when targeting Mac Catalyst, as using tintColor on iOS is proper.
#if targetEnvironment(macCatalyst)
let textInputTraits = myTextView.value(forKey: "textInputTraits") as? NSObject
textInputTraits?.setValue(UIColor.red, forKey: "insertionPointColor")
#endif
As of 2022 this works perfectly for both UITextField
and UITextView
on Mac Catalyst builds running on a Mac.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With