修改占位符颜色_如何在uisearchbar中更改占位符颜色

修改占位符颜色

访问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

Image for post
Code snippet for accessing TextField and changing its properties
用于访问TextField并更改其属性的代码段

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调用它:

Image for post
Code snippet for changing UISearchBar placeholder color
更改UISearchBar占位符颜色的代码段

Now with just a single line of code, you can change a UISearchBar's placeholder color.

现在只需一行代码,您就可以更改UISearchBar的占位符颜色。

searchBar.changePlaceholderColor(UIColor.orange)
Image for post
Output: placeholder color change
输出:占位符颜色变化

结论 (Conclusion)

Thank you for reading. I hope this article helps you. Do share your valuable feedback.

感谢您的阅读。 希望本文对您有所帮助。 分享您的宝贵意见。

其他文章 (Other Articles)

翻译自: https://medium.com/better-programming/how-to-change-the-placeholder-color-in-a-uisearchbar-1f47e5266e10

修改占位符颜色

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值