如何更改UISearchBar图标的颜色? [英] How to change the color of the UISearchBar Icon?

查看:126
本文介绍了如何更改UISearchBar图标的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何修改原来的 searchIcon 的颜色。

I don't know how to modify the original searchIcon's color.

推荐答案

您可以使用白色搜索图标的自定义图像,因为搜索栏不会修改您提供的图像。要设置自定义图像,请使用此方法。 (链接到文档。

You can use a custom image of a white search icon, as the search bar will not modify your supplied image. To set a custom image, use this method. (Link to documentation.)

- (void)setImage:(UIImage *)iconImage
forSearchBarIcon:(UISearchBarIcon)icon
           state:(UIControlState)state;

示例代码:

[searchBar setImage:[UIImage imageNamed:@"SearchIcon"]
   forSearchBarIcon:UISearchBarIconSearch
              state:UIControlStateNormal];

在Swift中:

searchBar.setImage(UIImage(named: "SearchIcon"), for: .search, state: .normal)

这篇关于如何更改UISearchBar图标的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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