日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UISeatchBar

發布時間:2025/5/22 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UISeatchBar 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1、修改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.subviews?objectAtIndex:0]removeFromSuperview];?
  •   2、

        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;

        //為UISearchBar添加背景圖片

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

        UIImageView?*bgImage?=?[[UIImageView?alloc]?initWithImage:[UIImage?imageNamed:@"Images/search_bar_bg.png"]];        [segment?addSubview:?bgImage]; ?

        //<---背景圖片

        [self.view?addSubview:m_searchBar];

        [m_searchBar?release];?

    3:取消UISearchBar調用的鍵盤

  • [searchBar?resignFirstResponder];??
  • 添加UISearchBar的兩種方法:

    代碼

  • UISearchBar?*mySearchBar?=?[[UISearchBar?alloc]?
  • initWithFrame:CGRectMake(0.0,?0.0,?self.view.bounds.size.width,?45)];??????????
  • ?mySearchBar.delegate?=?self;??????????
  • ?mySearchBar.showsCancelButton?=?NO;??????????
  • ?mySearchBar.barStyle=UIBarStyleDefault; ? ?? ? ??
  • ?mySearchBar.placeholder=@"Enter?Name?or?Categary"; ?//輸入框中原始的文字 ? ? ? ??
  • mySearchBar.keyboardType=UIKeyboardTypeNamePhonePad;???????????
  • [self.view?addSubview:mySearchBar];??????????
  • ?[mySearchBar?release];????
  • 3.在?tableview上添加:???

    代碼 ?

         ??//add?Table ?

    ? ? ? ? UITableView?*myBeaconsTableView?=?[[UITableView?alloc] ??initWithFrame:CGRectMake(0,?0,?self.view.bounds.size.width,?self.view.bounds.size.height-40) ? ?? style:UITableViewStylePlain];

    ? ? ? ??myBeaconsTableView.backgroundColor?=?[UIColor?whiteColor];

    ? ? ? ??myBeaconsTableView.delegate=self;

    ? ? ? ?myBeaconsTableView.dataSource=self;

    ? ? ? ? [myBeaconsTableView?setRowHeight:40];

    ? ? ? ? //?Add?searchbar ??

    ? ? ? ??searchBar?=?[[UISearchBar?alloc]?initWithFrame:CGRectMake(0.0,?0.0,?self.view.bounds.size.width,?40)]; ?

    ? ? ? ??searchBar.placeholder=@"Enter?Name"; ?

    ? ? ? ??searchBar.delegate?=?self; ?

    ? ? ? ??myBeaconsTableView.tableHeaderView?=?searchBar; ?

    ? ? ? ??searchBar.autocorrectionType?=?UITextAutocorrectionTypeNo; ?

    ? ? ? ??searchBar.autocapitalizationType?=?UITextAutocapitalizationTypeNone; ?

    ? ? ? ? [searchBar?release]; ?

    ? ? ? ? [self.view?addSubview:myBeaconsTableView]; ?

    ? ? ? ? [myBeaconsTableView?release]; ?

    ?

    ?4.刪除搜索框背景

    ? ? [[mSearchBar.subviewsobjectAtIndex:0]removeFromSuperview];

    ? ? // 刪除searchBar輸入框的背景

    ? ? for (UIView* subview? in mSearchBar.subviews) {

    ? ? ? ? if ([subview isKindOfClass:[UITextField class]]) {

    ? ? ? ? ? ? UITextField * searchField = (UITextField*)subview;

    ? ? ? ? ? ? searchField.leftView=nil;//隱藏搜索小圖標

    ? ? ? ? ? ? [searchField setBackground:nil];

    ? ? ? ? ? ? [searchField setBorderStyle:UITextBorderStyleNone];

    ? ? ? ? ? ? break;

    ? ? ? ? }

    ? ? }

    轉載于:https://www.cnblogs.com/Cristen/archive/2012/11/20/2779155.html

    總結

    以上是生活随笔為你收集整理的UISeatchBar的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。