zoukankan      html  css  js  c++  java
  • IOS searchBar去掉背景

       修改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];

  • 相关阅读:
    GTD时间管理(1)---捕获搜集
    ios面试总结-
    Swift入门篇-结构体
    Swift入门篇-闭包和函数
    swift入门篇-函数
    Swift入门篇-集合
    Swift入门篇-循环语句
    Swift入门篇-基本类型(3)
    Swift入门篇-基本类型(2)
    Swift入门篇-基本类型(1)
  • 原文地址:https://www.cnblogs.com/zhangyuqing/p/3525154.html
Copyright © 2011-2022 走看看