UINavigationItem 中的搜索栏
我使用以下代码在 UINavigationItem 中添加了一个搜索栏:
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
[searchBar sizeToFit];
searchBar.delegate = self;
self.navigationItem.titleView = searchBar;
self.navigationItem.title = self.category.title;
[searchBar release];
但结果 UI 如下所示:
如何我可以更改搜索栏的颜色并使其与导航栏的背景相同吗?
谢谢。
I added a search bar in the UINavigationItem using the following code:
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
[searchBar sizeToFit];
searchBar.delegate = self;
self.navigationItem.titleView = searchBar;
self.navigationItem.title = self.category.title;
[searchBar release];
but the result UI is like this:
How can I change the color of the search bar and make it the same with the background of the navigation bar?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于 UINavigationBar,有多种方法可以操纵它的背景颜色:
对于搜索栏tintColor 是也可用。但在你的情况下,我建议继承 UISearchBar 并提供如下所示的实现,以完全摆脱后台绘制例程。在这种情况下,您将在透明工具栏上获得搜索栏,并且您将只需要管理 UINavigationBar 颜色。
For a UINavigationBar there is multiple ways to manipulate background color of it:
For a search bar tintColor is also available. But in your case I suggest to inherit form UISearchBar and provide implementation as shown below to get rid from background drawing routine totally. In this case you will get search bar on an transparent toolbar and will and you will need to manage only UINavigationBar color.
如果您查看 UISearchBar 上的文档,它具有属性“tintColor”。
将其设置为导航栏的颜色。
如果您不知道导航栏的颜色,请获取导航栏的tintColor。
您可能还想使用搜索栏的“半透明”属性。可能会工作得更好。
If you see the documentation on UISearchBar it has the property "tintColor".
Set that to color of the navigation bar.
If you do not know the color of navigationbar, get the tintColor of navigationBar.
You might also want to lay with the "translucent" property of the searchbar. Might work better.