如何以编程方式更改 mac Catalyst 上 UITextField 提示的颜色?
提示存在,但颜色与 UITextField 相同。
提示在 iOS 上显示正确的颜色。
我尝试失败.tintColor
代码 + iOS 和 Mac Catalyst 结果 https://i.stack.imgur.com/z69w4.jpg
经过大量搜索后,我想我已经找到了解决此问题的方法。您可以使用键值编码范例来获取insertionPointColor 属性(这是您最终需要设置的属性)。以下是将插入符号颜色设置为红色的示例。请注意,仅在针对 Mac Catalyst 时才执行此操作,因为在 iOS 上使用tintColor 是正确的。
#if targetEnvironment(macCatalyst)
let textInputTraits = myTextView.value(forKey: "textInputTraits") as? NSObject
textInputTraits?.setValue(UIColor.red, forKey: "insertionPointColor")
#endif
截至 2022 年,这对双方来说都非常有效UITextField
and UITextView
在 Mac 上 Catalyst 构建在 Mac 上运行。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)