UISearchBar 搜索框
2015-11-30 22:56
337 查看
UISearchBar 一般配合UITableView使用,当然也可以配合UITextView或者UIWebView使用。
先看他的几个属性:
[cpp] view
plaincopyprint?
@property(nonatomic) UIBarStyle barStyle; // default is UIBarStyleDefault (blue)
@property(nonatomic,assign) id<UISearchBarDelegate> delegate; // weak reference. default is nil
@property(nonatomic,copy) NSString *text; // current/starting search text
@property(nonatomic,copy) NSString *prompt; // default is nil
@property(nonatomic,copy) NSString *placeholder; // default is nil
@property(nonatomic) BOOL showsBookmarkButton; // default is NO
@property(nonatomic) BOOL showsCancelButton; // default is NO
@property(nonatomic) BOOL showsSearchResultsButton __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_2); // default is NO
@property(nonatomic, getter=isSearchResultsButtonSelected) BOOL searchResultsButtonSelected __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_2); // default is NO
- (void)setShowsCancelButton:(BOOL)showsCancelButton animated:(BOOL)animated __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);
@property(nonatomic,retain) UIColor *tintColor; // default is nil
@property(nonatomic,assign,getter=isTranslucent) BOOL translucent __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0); // Default is NO. Always YES if barStyle is set to UIBarStyleBlackTranslucent
// available text input traits
@property(nonatomic) UITextAutocapitalizationType autocapitalizationType; // default is UITextAutocapitalizationTypeNone
@property(nonatomic) UITextAutocorrectionType autocorrectionType; // default is UITextAutocorrectionTypeDefault
@property(nonatomic) UITextSpellCheckingType spellCheckingType; // default is UITextSpellCheckingTypeDefault
@property(nonatomic) UIKeyboardType keyboardType; // default is UIKeyboardTypeDefault
@property(nonatomic,copy) NSArray *scopeButtonTitles __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0); // array of NSStrings. no scope bar shown unless 2 or more items
@property(nonatomic) NSInteger selectedScopeButtonIndex __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0); // index into array of scope button titles. default is 0. ignored if out of range
@property(nonatomic) BOOL showsScopeBar __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0); // default is NO. if YES, shows the scope bar. call sizeToFit: to update frame
// 1pt wide images and resizable images will be scaled or tiled according to the resizable area, otherwise the image will be tiled
@property(nonatomic,retain) UIImage *backgroundImage __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0) UI_APPEARANCE_SELECTOR;
@property(nonatomic,retain) UIImage *scopeBarBackgroundImage __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0) UI_APPEARANCE_SELECTOR;
再来看他的委托方法:
[cpp] view
plaincopyprint?
@protocol UISearchBarDelegate <NSObject>
@optional
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar; // return NO to not become first responder
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar; // called when text starts editing
- (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 *)text __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_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
- (void)searchBarResultsListButtonClicked:(UISearchBar *)searchBar __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_2); // called when search results button pressed
- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);
@end
完了。
先看他的几个属性:
[cpp] view
plaincopyprint?
@property(nonatomic) UIBarStyle barStyle; // default is UIBarStyleDefault (blue)
@property(nonatomic,assign) id<UISearchBarDelegate> delegate; // weak reference. default is nil
@property(nonatomic,copy) NSString *text; // current/starting search text
@property(nonatomic,copy) NSString *prompt; // default is nil
@property(nonatomic,copy) NSString *placeholder; // default is nil
@property(nonatomic) BOOL showsBookmarkButton; // default is NO
@property(nonatomic) BOOL showsCancelButton; // default is NO
@property(nonatomic) BOOL showsSearchResultsButton __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_2); // default is NO
@property(nonatomic, getter=isSearchResultsButtonSelected) BOOL searchResultsButtonSelected __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_2); // default is NO
- (void)setShowsCancelButton:(BOOL)showsCancelButton animated:(BOOL)animated __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);
@property(nonatomic,retain) UIColor *tintColor; // default is nil
@property(nonatomic,assign,getter=isTranslucent) BOOL translucent __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0); // Default is NO. Always YES if barStyle is set to UIBarStyleBlackTranslucent
// available text input traits
@property(nonatomic) UITextAutocapitalizationType autocapitalizationType; // default is UITextAutocapitalizationTypeNone
@property(nonatomic) UITextAutocorrectionType autocorrectionType; // default is UITextAutocorrectionTypeDefault
@property(nonatomic) UITextSpellCheckingType spellCheckingType; // default is UITextSpellCheckingTypeDefault
@property(nonatomic) UIKeyboardType keyboardType; // default is UIKeyboardTypeDefault
@property(nonatomic,copy) NSArray *scopeButtonTitles __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0); // array of NSStrings. no scope bar shown unless 2 or more items
@property(nonatomic) NSInteger selectedScopeButtonIndex __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0); // index into array of scope button titles. default is 0. ignored if out of range
@property(nonatomic) BOOL showsScopeBar __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0); // default is NO. if YES, shows the scope bar. call sizeToFit: to update frame
// 1pt wide images and resizable images will be scaled or tiled according to the resizable area, otherwise the image will be tiled
@property(nonatomic,retain) UIImage *backgroundImage __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0) UI_APPEARANCE_SELECTOR;
@property(nonatomic,retain) UIImage *scopeBarBackgroundImage __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0) UI_APPEARANCE_SELECTOR;
再来看他的委托方法:
[cpp] view
plaincopyprint?
@protocol UISearchBarDelegate <NSObject>
@optional
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar; // return NO to not become first responder
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar; // called when text starts editing
- (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 *)text __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_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
- (void)searchBarResultsListButtonClicked:(UISearchBar *)searchBar __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_2); // called when search results button pressed
- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);
@end
完了。
相关文章推荐
- UIView 转 UIImage
- UIImagePickerController 图像选取器--在iPhone中调用照相机、照片库—IOS开发
- UIPickerView 选取器(滚轮)—IOS开发
- UESTC 1014 The King and King boss 鸽巢原理
- 从头认识java-11.2 "+"与StringBuilder
- 黑马程序员_javaGUI综合部件布局与事件处理
- Masonry + UIView Animations 注意事项
- Duilib源码分析(四)绘制管理器—CPaintManagerUI
- 理解 Android Build 系统
- 【LEETCODE】62-Unique Paths
- 快速排序--quickSort
- UICollectionView
- 容器总结——array、vector、deque
- 动态修改UINavigationBar的背景色
- description The resource identified by this request is only capable of generating responses with cha
- UI(一)
- request与response
- easy-ui 小白进阶史(二):操作数据,easy-ui操作
- ui 霓虹灯
- StringBuffer和StringBuilder