在Mac催化剂上更改UITextField的提示颜色 [英] Change prompt color for UITextField on mac catalyst

查看:79
本文介绍了在Mac催化剂上更改UITextField的提示颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Mac催化剂上以编程方式更改UITextField提示的颜色?

How can I programmatically change the color of the prompt on mac catalyst for an UITextField?

该提示存在,但颜色与UITextField相同.

The prompt exist but with the same color as UITextField.

提示符在iOS上显示正确的颜色.

The prompt is showing the right color on iOS.

我尝试 .tintColor

I unsuccessfully tried .tintColor

代码+ iOS和Mac Catalyst结果

推荐答案

经过大量搜索,我认为我已经找到了解决方法.您可以使用键值编码范例来获取insertPointPointColor属性(这是您最终需要设置的属性).这是将插入符号颜色设置为红色的示例.请注意,仅在将Mac Catalyst作为目标时才应执行此操作,因为在iOS上使用tintColor是正确的.

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

这篇关于在Mac催化剂上更改UITextField的提示颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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