如何更改搜索栏的颜色? [英] How to change color of Search Bar?

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

问题描述

我已经实现了搜索栏,我想更改搜索栏的颜色.我该怎么办?

I've implemented a Search Bar and I want to change color of Search Bar. How can I do that?

我尝试过:

self.mySearchBar.backgroundColor = [UIColor redColor];

但没有成功.

更新(已解决):

在使用以下代码定义背景色之前,我必须删除默认背景色.

I had to remove the default background color before I defined background color with the following code.

for (UIView *subview in mySearchBar.subviews) {
    if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
        [subview removeFromSuperview];
        break;
    }
} 

...所以代码将是下一个:

... so code would be next:

  for (UIView *subview in mySearchBar.subviews) {
      if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
          [subview removeFromSuperview];
          break;
      }
  } 

  self.mySearchBar.backgroundColor = [UIColor redColor];

推荐答案

尝试:

self.mySearchBar.barTintColor = [UIColor redColor];

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

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