UISearchBar 搜索框

来源:互联网 发布:并查集的数组 编辑:程序博客网 时间:2024/06/09 16:49

UISearchBar 一般配合UITableView使用,当然也可以配合UITextView或者UIWebView使用。

先看他的几个属性:

[cpp] view plaincopyprint?
  1. @property(nonatomic)        UIBarStyle              barStyle;              // default is UIBarStyleDefault (blue)  
  2. @property(nonatomic,assign) id<UISearchBarDelegate> delegate;              // weak reference. default is nil  
  3. @property(nonatomic,copy)   NSString               *text;                  // current/starting search text  
  4. @property(nonatomic,copy)   NSString               *prompt;                // default is nil  
  5. @property(nonatomic,copy)   NSString               *placeholder;           // default is nil  
  6. @property(nonatomic)        BOOL                    showsBookmarkButton;   // default is NO  
  7. @property(nonatomic)        BOOL                    showsCancelButton;     // default is NO  
  8. @property(nonatomic)        BOOL                    showsSearchResultsButton __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_2); // default is NO  
  9. @property(nonatomic, getter=isSearchResultsButtonSelected) BOOL searchResultsButtonSelected __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_2); // default is NO  
  10. - (void)setShowsCancelButton:(BOOL)showsCancelButton animated:(BOOL)animated __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);  
  11.   
  12. @property(nonatomic,retain) UIColor                *tintColor;             // default is nil  
  13. @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  
  14.   
  15. // available text input traits  
  16. @property(nonatomic) UITextAutocapitalizationType autocapitalizationType;  // default is UITextAutocapitalizationTypeNone  
  17. @property(nonatomic) UITextAutocorrectionType     autocorrectionType;      // default is UITextAutocorrectionTypeDefault  
  18. @property(nonatomic) UITextSpellCheckingType      spellCheckingType;       // default is UITextSpellCheckingTypeDefault  
  19. @property(nonatomic) UIKeyboardType               keyboardType;            // default is UIKeyboardTypeDefault  
  20.   
  21. @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  
  22. @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  
  23. @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  
  24.   
  25. // 1pt wide images and resizable images will be scaled or tiled according to the resizable area, otherwise the image will be tiled  
  26. @property(nonatomic,retain) UIImage *backgroundImage __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0) UI_APPEARANCE_SELECTOR;  
  27. @property(nonatomic,retain) UIImage *scopeBarBackgroundImage __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0) UI_APPEARANCE_SELECTOR;  



再来看他的委托方法:

[cpp] view plaincopyprint?
  1. @protocol UISearchBarDelegate <NSObject>  
  2.   
  3. @optional  
  4.   
  5. - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar;                      // return NO to not become first responder  
  6. - (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar;                     // called when text starts editing  
  7. - (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar;                        // return NO to not resign first responder  
  8. - (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar;                       // called when text ends editing  
  9. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText;   // called when text changes (including clear)  
  10. - (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0); // called before text changes  
  11.   
  12. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar;                     // called when keyboard search button pressed  
  13. - (void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar;                   // called when bookmark button pressed  
  14. - (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar;                    // called when cancel button pressed  
  15. - (void)searchBarResultsListButtonClicked:(UISearchBar *)searchBar __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_2); // called when search results button pressed  
  16.   
  17. - (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);  
  18.   
  19. @end  

完了。
0 0
原创粉丝点击