修改占位符颜色
访问UITextField (Accessing UITextField)
We know that Apple has not made it easy for us to access the UITextField
reference on different OS. So here is the code to help you safely access UITextField
across all iOS versions.
我们知道Apple并没有使我们容易在不同的操作系统上访问UITextField
引用。 因此,以下代码可帮助您跨所有iOS版本安全地访问UITextField
。

This will help us to customize the font, background color, search icon of UITextField
, and much more. Below is an example snippet:
这将帮助我们自定义字体,背景色, UITextField
搜索图标等。 以下是一个示例片段:
searchBar.textField?.textColor = UIColor.gray
searchBar.textField?.font = // Your font
更改占位符颜色 (Change Placeholder Color)
Note: This will not work if you call in viewDidLoad
. Call it in viewDidAppear
:
注意:如果您在viewDidLoad
调用,这将不起作用。 在viewDidAppear
调用它:

Now with just a single line of code, you can change a UISearchBar
's placeholder color.
现在只需一行代码,您就可以更改UISearchBar
的占位符颜色。
searchBar.changePlaceholderColor(UIColor.orange)

结论 (Conclusion)
Thank you for reading. I hope this article helps you. Do share your valuable feedback.
感谢您的阅读。 希望本文对您有所帮助。 分享您的宝贵意见。
其他文章 (Other Articles)
修改占位符颜色