iPhone开发UISearchBar学习是本文要学习的内容,主要介绍了UISearchBar的使用,不多说,我们先来看详细内容。关于UISearchBar的一些问题。

1、修改UISearchBar的背景颜色

UISearchBar是由两个subView组成的,一个是UISearchBarBackGround,另一个是UITextField. 要IB中没有直接操作背景的属性。方法是直接将 UISearchBarBackGround移去

  1. seachBar=[[UISearchBar alloc] init];
  2. seachBar.backgroundColor=[UIColor clearColor];
  3. for (UIView *subview in seachBar.subviews)
  4. {
  5. if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
  6. {
  7. [subview removeFromSuperview];
  8. break;
  9. }
  10. }

第二种解决的方法:

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

2、

  1. UISearchBar* m_searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 44, 320, 41)];
  2. m_searchBar.delegate = self;
  3. m_searchBar.barStyle = UIBarStyleBlackTranslucent;
  4. m_searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
  5. m_searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
  6. m_searchBar.placeholder = _(@"Search");
  7. m_searchBar.keyboardType =  UIKeyboardTypeDefault;
  8. //为UISearchBar添加背景图片
  9. UIView *segment = [m_searchBar.subviews objectAtIndex:0];
  10. UIImageView *bgImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Images/search_bar_bg.png"]];
  11. [segment addSubview: bgImage];
  12. //<---背景图片
  13. [self.view addSubview:m_searchBar];
  14. [m_searchBar release];

3:取消UISearchBar调用的键盘

  1. [searchBar resignFirstResponder];

添加UISearchBar的两种方法:

代码

  1. UISearchBar *mySearchBar = [[UISearchBar alloc]
  2. initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, 45)];
  3. mySearchBar.delegate = self;
  4. mySearchBar.showsCancelButton = NO;
  5. mySearchBar.barStyle=UIBarStyleDefault;
  6. mySearchBar.placeholder=@"Enter Name or Categary";
  7. mySearchBar.keyboardType=UIKeyboardTypeNamePhonePad;
  8. [self.view addSubview:mySearchBar];
  9. [mySearchBar release];

在 tableview上添加:

代码

  1. //add Table
  2. UITableView *myBeaconsTableView = [[UITableView alloc]
  3. initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height-40)
  4. style:UITableViewStylePlain];
  5. myBeaconsTableView.backgroundColor = [UIColor whiteColor];
  6. myBeaconsTableView.delegate=self;
  7. myBeaconsTableView.dataSource=self;
  8. [myBeaconsTableView setRowHeight:40];
  9. // Add searchbar
  10. searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, 40)];
  11. searchBar.placeholder=@"Enter Name";
  12. searchBar.delegate = self;
  13. myBeaconsTableView.tableHeaderView = searchBar;
  14. searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
  15. searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
  16. [searchBar release];
  17. [self.view addSubview:myBeaconsTableView];
  18. [myBeaconsTableView release];

小结:iPhone开发UISearchBar学习的内容介绍完了,希望本文对你有所帮助

copy from http://mobile.51cto.com/iphone-280122.htm

关于UISearchBar的更多相关文章

  1. iOS 如何自定义UISearchBar 中textField的高度

    iOS 如何自定义UISearchBar 中textField的高度 只需设置下边的方法就可以 [_searchBar setSearchFieldBackgroundImage:[UIImage i ...

  2. iOS之搜索框UISearchController的使用(iOS8.0以后替代UISearchBar+display)

    在iOS 8.0以上版本中, 我们可以使用UISearchController来非常方便地在UITableView中添加搜索框. 而在之前版本中, 我们还是必须使用UISearchBar + UISe ...

  3. 更改UIsearchbar 的背景和cancel按钮(转)

    修改背景 searchbar =[[UISearchBar alloc]initWithFrame:CGRectMake(,KTopBarHeight, , KTopBarHeight)]; sear ...

  4. UISearchBar控件-让我们来搞定!(转)

    转载自:http://blog.sina.com.cn/s/blog_7b9d64af0101dfg8.html     最近用到搜索功能.于是,经过不断的研究,终于,有点懂了. 那就来总结一下吧,好 ...

  5. iOS开发——UI进阶篇(十九)UISearchBar控件简介

    最近用到搜索功能.总结一下 搜索,无疑可以使用UISearchBar控件! 那就先了解一下UISearchBar控件吧! UISearchBar控件就是要为你完成搜索功能的一个专用控件.它集成了很多你 ...

  6. IOS开发UISearchBar失去第一响应者身份后,取消按钮不执行点击事件的问题

    在iOS开发中,使用UISearchBar的时候,当搜索框失去焦点的时候,取消按钮是默认不能点击的,如图按钮的颜色是灰色的:  这是因为此时取消按钮的enabled属性被设置为NO了,那么当我们需要让 ...

  7. 修改UISearchBar的背景颜色

    当你看到这篇博客你就已经发现了用_searchBar.backgroundColor = [UIColor clearColor];来设置UISearchBar的颜色完全没有效果: 并且,有些方法是想 ...

  8. iOS UISearchBar 设置取消按钮,回收键盘,并修改cancel为“取消”

    继承协议: UISearchBarDelegate 在代理方法中设置: #pragma mark --- 搜索框开始编辑 --- - (void)searchBarTextDidBeginEditin ...

  9. iOS开发之直接使用UISearchBar

    iOS开发中经常需要使用SearchBar,我们可以选择使用UISearchBar+UISearchController或者UISearchBar+UISearchDisplayController( ...

  10. 自定义UISearchBar

    先上系统默认的UISearchBar,然后用KVO修改 UISearchBar *searchBar = [[UISearchBar alloc]initWithFrame:_topView.boun ...

随机推荐

  1. Codeforces Round #345 (Div. 2) E. Table Compression(并查集)

    传送门 首先先从小到大排序,如果没有重复的元素,直接一个一个往上填即可,每一个数就等于当前行和列的最大值 + 1 如果某一行或列上有重复的元素,就用并查集把他们连起来,很(不)显然,处于同一行或列的相 ...

  2. BZOJ2780 [Spoj]8093 Sevenk Love Oimaster 【广义后缀自动机】

    题目 Oimaster and sevenk love each other. But recently,sevenk heard that a girl named ChuYuXun was dat ...

  3. bzoj1734 [Usaco2005 feb]Aggressive cows 愤怒的牛 二分答案

    [Usaco2005 feb]Aggressive cows 愤怒的牛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 407  Solved: 325[S ...

  4. oracle连接封装方法

    public static void updateSqlOracle(String sqlstr,String linkIP,String username,String password) thro ...

  5. Codeforces956D. Contact ATC

    $n \leq 100000$个飞机在坐标轴上,给坐标给速度,坐标速度异号,还有一个风速在$[-w,w]$区间,$w$比最小的速度绝对值要小.由于风速不知道,所以问有多少对飞机可能在原点相遇. 思维定 ...

  6. MongoDB_副本集集群模式

    主从模式: 在10.3.13.213 主节点, 10.3.2.33 从节点.mongodb 安装路径均为:/usr/local/server/mongodb 参考文章:http://www.lance ...

  7. linux-起步

    学习网站: linux中国开源社区 Vmware下载与安装 https://blog.csdn.net/Ywaken/article/details/78839005 https://blog.csd ...

  8. 用delphi写多屏幕程序

    http://blog.csdn.net/zyyjc/article/details/6530728 别现在有些POS机是双屏幕的(比如卡西瓦POS机),一个屏幕可以当顾客显示屏用,当闲时也可以显示一 ...

  9. Angular Material & Hello World

    前言 Angular Material(下称Material)的组件样式至少是可以满足一般的个人开发需求(我真是毫无设计天赋),也是Angular官方推荐的组件.我们通过用这个UI库来快速实现自己的i ...

  10. 某考试 T2 sum

    为什么其他人都是插值套插值啊,,,,就我是XJB做的吗2333 k次多项式的前缀和可以表示成k+1次多项式,用两次这个玩意就可以发现g可以表示成一个k+2次多项式. 然后我的做法是把g用拉格朗日插值+ ...