How to change UISearchBar Placeholder and image tint color?(如何更改 UISearchBar 占位符和图像色调颜色?)
问题描述
我已经尝试了几个小时的搜索结果,但我无法弄清楚这一点.也许这是不可能的.我正在尝试更改 UISearchBar 的占位符文本和放大镜的色调.如果这很重要,我只针对 iOS 8.0+.这是我的代码以及它现在的样子:
I've been trying search results for hours, but I can't get this figured out. Perhaps it isn't possible. I'm trying to change the tint color of the placeholder text and magnifying glass of a UISearchBar. I'm only targeting iOS 8.0+ if that matters. Here's my code and what it looks like now:
我希望搜索和放大镜是白色的,或者可能是深绿色.
I'd like for the search and magnifying glass to be white, or perhaps a dark green.
推荐答案
如果您有可以使用的自定义图像,您可以使用类似于以下内容的方式设置图像并更改占位符文本颜色:
If you have a custom image you could use, you can set the image and change the placeholder text color using something similar to the following:
在该示例中,我使用了紫色颜色,而您可以使用 + (UIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha
创建自定义深绿色的方法.
In that example I used purpleColor, instead you can use the + (UIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha
method to create your custom dark green color.
我刚刚意识到你正在用swift写它......呃.快速输入这个,所以我没有在 Obj-C 中留下答案.
I just realized you were writing it in swift... duh. Quickly typed this out so I didn't leave the answer in just Obj-C.
Swift 3.0
这篇关于如何更改 UISearchBar 占位符和图像色调颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!