欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS App開發(fā)中UISearchBar搜索欄組件的基本用法整理

 更新時間:2016年05月19日 09:25:48   作者:iOS UI  
iOS開發(fā)組件中自帶的UISearchBar提供了很多基礎和好用的搜索欄UI功能,下面就來總結一下iOS App開發(fā)中UISearchBar搜索欄組件的基本用法整理,需要的朋友可以參考下

基本屬性

復制代碼 代碼如下:

@UISearchBar search = [[UISearchBar alloc]initWithFrame:CGRectMake(0,44,320,120)];

pragma mark -基本設置

復制代碼 代碼如下:

//控件的樣式 默認--0白色,1是黑色風格

/*
UIBarStyleDefault          = 0,
UIBarStyleBlack            = 1,
search.barStyle =UIBarStyleDefault;
/*

UISearchBarStyleDefault,
// currently UISearchBarStyleProminent

UISearchBarStyleProminent, // used my Mail, Messages and Contacts(provides no default background color or image but will display one if customized as such系統(tǒng)提供的顏色和圖片無效,自定制有效)

     UISearchBarStyleMinimal    // used by Calendar, Notes and Music

     */

    search.searchBarStyle =UISearchBarStyleDefault;

    // 控件上面的顯示的文字

    search.text =@"HMT";

    // 顯示在頂部的單行文字,通常作為一個提示行

    search.prompt =@"DOTA";

    // 半透明的提示文字,輸入搜索內(nèi)容消失

    search.placeholder =@"請輸入要搜索的詞語";

    // bar的顏色(具有漸變效果)搜索欄閃動條和選擇欄邊框,取消按鈕和選擇欄被選中時候都會變成設置的顏色

    search.tintColor = [UIColor redColor];

    // 除搜索欄框框,就像貼了一張鏤空了搜索欄的顏色貼圖,不影響其他任何設置的顏色

    search.barTintColor = [UIColor whiteColor];

    // 指定控件是否會有透視效果

    search.translucent =YES;

    // 設置在什么的情況下自動大寫

    /*

     UITextAutocapitalizationTypeNone,             //除非自己點擊大寫,否則永不大寫

     UITextAutocapitalizationTypeWords,            //以單詞來區(qū)分,每個單詞首字母大寫

     UITextAutocapitalizationTypeSentences,        //以句子來區(qū)分

     UITextAutocapitalizationTypeAllCharacters,    //所有字母全部大寫

     */

    search.autocapitalizationType =UITextAutocapitalizationTypeNone;

    // 對于文本對象自動校正風格(額,我也不知道有什么用)

    /*

     UITextAutocorrectionTypeDefault,

     UITextAutocorrectionTypeNo,

     UITextAutocorrectionTypeYes,

     */

    search.autocorrectionType =UITextAutocorrectionTypeNo;

    // 鍵盤的樣式(具體可參考文章UITableView詳解(一))

    search.keyboardType =UIKeyboardTypeNumberPad;


pragma mark - 設置搜索欄右邊按鈕圖標(UISearchBarIcon)
復制代碼 代碼如下:

    // 是否在控件的右端顯示一個書的按鈕

    search.showsBookmarkButton =YES;

    // 是否顯示cancel按鈕(靜態(tài))

    //search.showsCancelButton = YES;

    // 是否顯示cancel按鈕(帶有動畫效果)

    [search setShowsCancelButton:YES animated:YES];

    // 是否在控件的右端顯示搜索結果按鈕(圖形是一個圓里面放著一個向下的箭頭)

    search.showsSearchResultsButton =YES;

    // 搜索結果按鈕是否被選中

    search.showsSearchResultsButton =YES;

    // 設置控件的右端顯示搜索結果按鈕處 --- 可用圖片替換掉

    [search setImage:[UIImage imageNamed:@"qiyi.png"]forSearchBarIcon:UISearchBarIconResultsList state:UIControlStateNormal];


pragma mark - 搜索欄下部選擇欄
復制代碼 代碼如下:

    // 搜索欄下部的選擇欄,數(shù)組里面的內(nèi)容是按鈕的標題

    search.scopeButtonTitles = [NSArray arrayWithObjects:@"iOS",@"Android",@"iPhone",nil];

    // 進入界面,搜索欄下部的默認選擇欄按鈕的索引(也就是第一出現(xiàn)在哪個選擇欄)

    search.selectedScopeButtonIndex =2;

    // 控制搜索欄下部的選擇欄是否顯示出來(顯示的話,就要修改search的frame,不顯示的話80就夠了)

    search.showsScopeBar =YES;


pragma mark - 設置控件圖片
復制代碼 代碼如下:

    // 設置控件背景圖片

    search.backgroundImage = [UIImage imageNamed:@"qiyi.png"];

    // 設置搜索欄下部背景圖片

    search.scopeBarBackgroundImage = [UIImage imageNamed:@"qiyi.png"];


pragma mark - 協(xié)議UISearchBarDelegate

(不解釋了,看名字,已經(jīng)很明顯了)

復制代碼 代碼如下:

@編輯文本

 // UISearchBar得到焦點并開始編輯時,執(zhí)行該方法

(BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar;           // return NO to not become first responder

(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar{          // called when text starts editing

          [searchBar setShowsCancelButton:YES animated:YES];   //  動畫顯示取消按鈕

}

(BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar;       // return NO to not resign first responder

(void)searchBarTextDidEndEditing:(UISearchBar *)searchBar;            // called when text ends editing

(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{   // called when text changes (including clear)

   @ 當搜索內(nèi)容變化時,執(zhí)行該方法。很有用,可以實現(xiàn)時實搜索

}


復制代碼 代碼如下:

(BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)textNS_AVAILABLE_IOS(3_0);                 // called before text changes
@按鈕點擊

(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar;     // called when keyboard search button pressed

(void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar;        // called when bookmark button pressed

(void)searchBarCancelButtonClicked:(UISearchBar *) searchBar{           // called when cancel button pressed

    [searchBar setShowsCancelButton:NO animated:NO];    // 取消按鈕回收

    [searchBar resignFirstResponder];                                // 取消第一響應值,鍵盤回收,搜索結束

}

(void)searchBarResultsListButtonClicked:(UISearchBar *)searchBarNS_AVAILABLE_IOS(3_2);// called when search results button pressed

(void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScopeNS_AVAILABLE_IOS(3_0);

數(shù)據(jù)刷選類:NSPredicate

復制代碼 代碼如下:

@假設: NSArray array = [[NSArray alloc]initWithObjects:@"luna",@"moon",@"",@"lion",@"coco", nil];

// 數(shù)據(jù)的處理主要發(fā)生在這個方法中

(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{

    // 方法一:([c]不區(qū)分大小寫[d]不區(qū)分發(fā)音符號即沒有重音符號[cd]既不區(qū)分大小寫,也不區(qū)分發(fā)音符號。)

    NSPredicate * predicate = [NSPredicate predicateWithFormat:@"SELF CONTAINS [cd] %@",searchText];

   //  數(shù)組提供的快速遍歷,返回的類型是NSArray

   NSLog(@"%@",[ _array filteredArrayUsingPredicate:predicate]);

    // 方法二:

    for (int i = 0; i count]; i++) {

        if ([predicate evaluateWithObject:[ _array objectAtIndex:i]]) {

            NSLog(@"%@",[arrayobjectAtIndex:i]);

        }

    }

}

相關文章

最新評論