UISearchBar是由两个subView组成的,一个是UISearchBarBackGround,另一个是UITextField. 要IB中没有直接操作背景的属性。方法一:是直接将 UISearchBarBackGround移去。方法二:是创建一个UIView设置其颜色加载到UISearchBarBaceGround上作为UISearchBar的背景颜色

方法一:

UISearchBar *seachBar=[[UISearchBar alloc] init];

//修改搜索框背景

seachBar.backgroundColor=[UIColor clearColor];

//去掉搜索框背景

//1.

[[searchbar.subviews objectAtIndex:0]removeFromSuperview];

//2.

for (UIView *subview in seachBar.subviews)

{

if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")])

{

[subview removeFromSuperview];

break;

}

}

//3自定义背景

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"40-di.png"]];

[mySearchBar insertSubview:imageView atIndex:1];

[imageView release];

//4输入搜索文字时隐藏搜索按钮,清空时显示

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {

searchBar.showsScopeBar = YES;

[searchBar sizeToFit];

[searchBar setShowsCancelButton:YES animated:YES];

return YES;

}

- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar {

searchBar.showsScopeBar = NO;

[searchBar sizeToFit];

[searchBar setShowsCancelButton:NO animated:YES];

return YES;

}

//改变搜索按钮文字

//改变UISearchBar取消按钮字体

for(id cc in [searchBar subviews])

{

if([cc isKindOfClass:[UIButton class]])

{

UIButton *btn = (UIButton *)cc;

[btn setTitle:@"搜索" forState:UIControlStateNormal];

}

方法二:

修改UISearchBar背景颜色

UISearchBar是由两个subView组成的,一个是UISearchBarBackGround,另一个是UITextField. 要IB中没有直接操作背景的属性。方法一:是直接将 UISearchBarBackGround移去。方法二:是创建一个UIView设置其颜色加载到UISearchBarBaceGround上作为UISearchBar的背景颜色

方法一:

UISearchBar *seachBar=[[UISearchBar alloc] init];

//修改搜索框背景

seachBar.backgroundColor=[UIColor clearColor];

//去掉搜索框背景

//1.

[[searchbar.subviews objectAtIndex:0]removeFromSuperview];

//2.

for (UIView *subview in seachBar.subviews)

{

if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")])

{

[subview removeFromSuperview];

break;

}

}

//3自定义背景

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"40-di.png"]];

[mySearchBar insertSubview:imageView atIndex:1];

[imageView release];

//4输入搜索文字时隐藏搜索按钮,清空时显示

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {

searchBar.showsScopeBar = YES;

[searchBar sizeToFit];

[searchBar setShowsCancelButton:YES animated:YES];

return YES;

}

- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar {

searchBar.showsScopeBar = NO;

[searchBar sizeToFit];

[searchBar setShowsCancelButton:NO animated:YES];

return YES;

}

//改变搜索按钮文字

//改变UISearchBar取消按钮字体

for(id cc in [searchBar subviews])

{

if([cc isKindOfClass:[UIButton class]])

{

UIButton *btn = (UIButton *)cc;

[btn setTitle:@"搜索" forState:UIControlStateNormal];

}

方法二:

UISearchBar* m_searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 44, 320, 41)];

m_searchBar.delegate = self;

m_searchBar.barStyle =UIBarStyleBlackTranslucent;

m_searchBar.autocorrectionType = UITextAutocorrectionTypeNo;

m_searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;

m_searchBar.placeholder = _(@"Search");

m_searchBar.keyboardType = UIKeyboardTypeDefault;

//--->背景图片

UIView *segment = [m_searchBar.subviews objectAtIndex:0];

UIImageView *bgImage = [[UIImageView alloc] initWithImage: [UIImageimageNamed:@"Images/search_bar_bg.png"]];

[segment addSubview: bgImage];

//<---背景图片

[self.view addSubview:m_searchBar];

[m_searchBar release];

修改UISearchBar背景颜色的更多相关文章

  1. jquery入门 修改网页背景颜色

    我们在浏览一些网站,尤其是一些小说网站的时候,都会有修改页面背景颜色的地方,这个功能使用jquery很容易实现. 效果图: show you code: <!doctype html> & ...

  2. 【BIRT】修改主题背景颜色

    下图是BIRT默认的颜色配置,为了跟系统颜色格局相一致,此处需要对颜色进行修改; 下面简单介绍了如何修改不同位置的背景颜色 对应文件地址均在目录:../webcontent/birt/styles下 ...

  3. 【VS开发】修改窗口背景颜色大全

    如何修改frame窗口的背景颜色?  MDI窗口的客户区是由frame窗口拥有的另一个窗口覆盖的.为了改变frame窗口背景的颜色,只需要这个客户区的背景颜色就可以了.你必须自己处理WM_ERASEB ...

  4. 修改cocos2dx 背景颜色

    只需要在AppDelegate的设置FPS后面加入一行: glClearColor(1.0, 1.0, 1.0, 1.0); 同理如果要修改成其它颜色,只需修改里面的值即可( r, g, b, a);

  5. 修改UISearchBar背景

    转载:http://blog.csdn.net/favormm/archive/2010/11/30/6045463.aspx UISearchBar是由两个subView组成的,一个是UISearc ...

  6. WPF使用Fluent.Ribbon修改标题栏背景颜色

    使用NuGet安装:Install-Package Fluent.Ribbon 修改App.xaml: <Application.Resources> <!-- Attach def ...

  7. 修改hbuilder背景颜色为护眼模式

    复制以下代码,保存为.tmTheme文件导入HBuilder <?xml version="1.0" encoding="UTF-8"?> < ...

  8. Intellij IDEA 修改编辑器背景颜色

    对眼睛有益的RGB数值分别是(199,237,204)

  9. uniapp-uni.setNavigationBarColor 动态修改顶部背景颜色

    uni.setNavigationBarColor({ frontColor: '#ffffff', backgroundColor: "#3583ff" })

随机推荐

  1. IE 创建条件样式

    1.HTML 注释 <div id="header">Header Section</div> <!-- End Header Section Con ...

  2. Android UI ActionBar功能-自动隐藏 Action Bar

    为了使ActionBar不影响Activity的布局内容,我们还可以设置ActionBar,将其设置为透明,并且让Activity是头部自动空出一个ActionBar的空间: 官方文档:http:// ...

  3. 【每天一个Linux命令】13. Linux中whereis命令的用法

      命令用途 whereis命令用来查找命令的位置,包括执行文件.源代码和手册页文件 命令用法 1. 查找指定命令<command>的位置,包括执行文件.源代码和手册页文件 格式:wher ...

  4. JSEL 表达式

    JSTL标签库的使用是为类弥补html表的不足,规范自定义标签的使用而诞生的.在告别modle1模式开发应用程序后,人们开始注重软件的分层设计,不希望在jsp页面中出现java逻辑代码,同时也由于自定 ...

  5. Openlayers 自定义控件

    OpenLayers.Control.YourControl = OpenLayers.Class(OpenLayers.Control, { // may private properties he ...

  6. Linux学习之sed命令详解

    概述 sed是stream editor的简称,也就是流编辑器.它一次处理一行内容,处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命令处理缓冲区 ...

  7. 易宝网上支付平台的PHP接口代码

    本代码参照自韩顺平149讲视频后5讲,需要学习的朋友可以参考本代码 这是测试图片: 以下是代码部分: <?php function HmacMd5($data, $key) { //需要配置环境 ...

  8. Java 拾遗

    1.选择表达式中的类型转换 public class Test { public void static main(String args[]){ int i = 5; System.out.prin ...

  9. 20.org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

    org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actua ...

  10. C#版-百度网盘API的实现(一)

    在这篇文章中,楼主将会给大家介绍一下,通过C# winform程序在后台模拟用户登陆百度网盘的基本思路 首先了解下模拟登陆的流程,如下: 一,访问http://www.baidu.com网站,获取BA ...