首页 > 其他 > 详细

IOS searchBar去掉背景

时间:2014-01-18 18:45:56      阅读:439      评论:0      收藏:0      [点我收藏+]

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

 

  seachBar=[[UISearchBar alloc] init];
  seachBar.backgroundColor=[UIColor clearColor];
  for (UIView *subview in seachBar.subviews)
  {
  if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
  {
  [subview removeFromSuperview];
  break;
  }
  }

 

添加searchBar的背景图片

  searchBar.delegate = self;
  searchBar.barStyle = UIBarStyleBlackTranslucent;
  searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
  searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
  searchBar.placeholder = _(@"Search");
  searchBar.keyboardType = UIKeyboardTypeDefault;
  //为UISearchBar添加背景图片
  UIView *segment = [searchBar.subviews objectAtIndex:0];
  UIImageView *bgImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"search_bar_bg.png"]];
  [seachBar addSubview: bgImage];
  [self.view addSubview:searchBar];

关闭键盘

[searchBar  resignFirstResponder];

IOS searchBar去掉背景

原文:http://www.cnblogs.com/zhangyuqing/p/3525154.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!