@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系統提供的顏色和圖片無效,自定制有效)
?? ? UISearchBarStyleMinimal ? ?// used by Calendar, Notes and Music
?? ? */
? ? search.searchBarStyle?=UISearchBarStyleDefault;
?? ?
? ??//?控件上面的顯示的文字
? ? search.text?=@"HMT";
?? ?
? ??//?顯示在頂部的單行文字,通常作為一個提示行
? ? search.prompt?=@"DOTA";
?? ?
? ??//?半透明的提示文字,輸入搜索內容消失
? ? search.placeholder?=@"請輸入要搜索的詞語";
?? ?
? ??// bar的顏色(具有漸變效果)搜索欄閃動條和選擇欄邊框,取消按鈕和選擇欄被選中時候都會變成設置的顏色
? ? search.tintColor?= [UIColor?redColor];
?? ?
? ??//?除搜索欄框框,就像貼了一張鏤空了搜索欄的顏色貼圖,不影響其他任何設置的顏色
? ? search.barTintColor?= [UIColor?whiteColor];
?? ?
? ??//?指定控件是否會有透視效果
? ? search.translucent?=YES;
?? ?
? ??//?設置在什么的情況下自動大寫
? ??/*
?? ? UITextAutocapitalizationTypeNone, ? ? ? ? ? ? //除非自己點擊大寫,否則永不大寫
?? ? UITextAutocapitalizationTypeWords,? ? ? ? ? ? //以單詞來區分,每個單詞首字母大寫
?? ? UITextAutocapitalizationTypeSentences,? ? ? ? //以句子來區分
?? ? UITextAutocapitalizationTypeAllCharacters,? ? //所有字母全部大寫
?? ? */
? ? search.autocapitalizationType?=UITextAutocapitalizationTypeNone;
?? ?
? ??//?對于文本對象自動校正風格(額,我也不知道有什么用)
? ??/*
?? ? UITextAutocorrectionTypeDefault,
?? ? UITextAutocorrectionTypeNo,
?? ? UITextAutocorrectionTypeYes,
?? ? */
? ? search.autocorrectionType?=UITextAutocorrectionTypeNo;
?? ?
? ??//?鍵盤的樣式(具體可參考文章UITableView詳解(一))
? ? search.keyboardType?=UIKeyboardTypeNumberPad;
?? ?
#pragma mark -?設置搜索欄右邊按鈕圖標(UISearchBarIcon)
?? ?
? ??//?是否在控件的右端顯示一個書的按鈕
? ? search.showsBookmarkButton?=YES;
?? ?
? ??//?是否顯示cancel按鈕(靜態)
? ??//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 -?搜索欄下部選擇欄
?? ?
? ??//?搜索欄下部的選擇欄,數組里面的內容是按鈕的標題
? ? search.scopeButtonTitles?= [NSArray?arrayWithObjects:@"iOS",@"Android",@"iPhone",nil];
?? ?
? ??//?進入界面,搜索欄下部的默認選擇欄按鈕的索引(也就是第一出現在哪個選擇欄)
? ? 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 -?協議UISearchBarDelegate
(不解釋了,看名字,已經很明顯了)
@編輯文本
?// UISearchBar得到焦點并開始編輯時,執行該方法
- (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)
? ? ? ? ? ? ? ??
? ?@ 當搜索內容變化時,執行該方法。很有用,可以實現時實搜索
}
- (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);
- 前言
- UITableView詳解(UITableViewCell(一)重中之重)
- UITableView詳解(UITableViewCell(二) 自定義cell)
- UITableView詳解(UITableViewCell(三) cell根據文本長度來自動調整cell高度)
- UITableView詳解(UITableViewCell(四) 增加 刪除 移動)
- UITabBarController詳解(一)UITabBarController的介紹和設置(偷了點懶,直接用了ARC)
- UITabBarController詳解(二)UITabBarController的代理方法以及模態顯示
- UISearchBar詳解(一)基本屬性
- UISearchBar詳解(二)數據刷選類:NSPredicate
- UISearchDisplayController 的使用
- UINavigationController詳解(一)
- UINavigationController詳解(二)UINavigationBar(UIBarButtonItem)
- UINavigationController詳解(三)UIToolBar
- UINavigationController詳解(四)iOS7新特性
- UIScrollView控件詳解
- UISwitch用法-以及-自定義UISwitch控件
- UIAlertView用法
- UILabel 的常見屬性和方法:
- UIPickerView(滾動選擇控制器)
- UIActivityIndicatorView(活動指示器 ---------> 網絡卡后加載,畫面,圖像加載閃爍的圓圈)
- UIStepper
- UIImagePickerController--------圖片選取器
- UITextView
- UITabBarController詳解(三)自定義UITabBarController
- UIWebView基本介紹