UISearchBar取消按钮颜色? [英] UISearchBar cancel button color?

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

问题描述

当我在Interface Builder中将UISearchBar放入我的视图,并将其样式更改为黑色不透明时,取消按钮保持不适合的蓝色/灰色,不会变黑。

When I drop a UISearchBar into my view inside Interface Builder, and change its style to Black Opaque, the cancel button stays unfittingly blue / gray and doesn't become black.

如何使取消按钮变为黑色?

How can I make the cancel button black?

编辑:它的工作方式如下:

It does work like this:

// Assume a UISearchBar searchBar.
NSArray *subviews = [searchBar subviews];

// The index depends on how you configure the searchBar.
UIButton *cancelButton = [subviews objectAtIndex:3];

// Set the style to "normal" style.
[cancelButton setStyle:0];

但是 setStyle:私人框架,所以这可能是一个问题,当提交应用程序到苹果。

But the setStyle: method is from a private framework, so this might be an issue when submitting the app to Apple.

推荐答案

我使用了一些这样的工作,我:

I used some thing like this and worked with me:

[[UIBarButtonItem appearanceWhenContainedIn: [UISearchBar class], nil] setTintColor:[UIColor blackColor]];

它将取消按钮的颜色更改为黑色。

it changed the cancel button color to black.

更新(对于iOS 9.0),不推荐使用 appearanceWhenContainedIn 的方法,而改用 appearanceWhenContainedInInstancesOfClasses

Update for iOS 9.0, the method appearanceWhenContainedIn is deprecated, use appearanceWhenContainedInInstancesOfClasses instead:

[[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setTintColor:[UIColor blackColor]];

在Swift中:

(UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self])).tintColor = UIColor.blackColor()

这篇关于UISearchBar取消按钮颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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