- (void)setSearchFieldBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state;
- (UIImage *)searchFieldBackgroundImageForState:(UIControlState)state;
这一对方法用于设置和获取搜索框中TextField的背景图案
- (void)setImage:(UIImage *)iconImage forSearchBarIcon:(UISearchBarIcon)icon state:(UIControlState)state ;
- (UIImage *)imageForSearchBarIcon:(UISearchBarIcon)icon state:(UIControlState)state ;
这一对方法用于获取和设置搜索栏icon图片的图案
- (void)setScopeBarButtonBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state;
- (UIImage *)scopeBarButtonBackgroundImageForState:(UIControlState)state;
这一对方法用于设置和获取搜索框的附加选择按钮视图的背景图案
- (void)setScopeBarButtonDividerImage:(UIImage *)dividerImage forLeftSegmentState:(UIControlState)leftState rightSegmentState:(UIControlState)rightState;
- (UIImage *)scopeBarButtonDividerImageForLeftSegmentState:(UIControlState)leftState rightSegmentState:(UIControlState)rightState;
这一对方法用于获取和设置附加选择按钮视图中切换按钮的图案
- (void)setScopeBarButtonTitleTextAttributes:(NSDictionary *)attributes forState:(UIControlState)state;
- (NSDictionary *)scopeBarButtonTitleTextAttributesForState:(UIControlState)state;
这一对方法用于设置和获取切换按钮标题文字的字体属性字典
@property(nonatomic) UIOffset searchFieldBackgroundPositionAdjustment;
搜索文字在搜索框中的位置偏移
@property(nonatomic) UIOffset searchTextPositionAdjustment;
textfield在搜索框中的位置偏移
- (void)setPositionAdjustment:(UIOffset)adjustment forSearchBarIcon:(UISearchBarIcon)icon;
- (UIOffset)positionAdjustmentForSearchBarIcon:(UISearchBarIcon)icon;
设置搜索栏中图片的位置偏移,图片的枚举如下:
typedef NS_ENUM(NSInteger, UISearchBarIcon) {
UISearchBarIconSearch, //搜索图标
UISearchBarIconClear, // 清除图标
UISearchBarIconBookmark, // 书本图标
UISearchBarIconResultsList, // 结果列表图标
};
下面是搜索框控件的一些代理方法:
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar;
将要开始编辑时的回调,返回为NO,则不能编辑
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar;
已经开始编辑时的回调
- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar;
将要结束编辑时的回调
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar;
已经结束编辑的回调
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText; 编辑文字改变的回调
- (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text ;
编辑文字改变前的回调,返回NO则不能加入新的编辑文字
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar;
搜索按钮点击的回调
- (void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar;
书本按钮点击的回调
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar;
取消按钮点击的回调
- (void)searchBarResultsListButtonClicked:(UISearchBar *)searchBar;
搜索结果按钮点击的回调
- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope;
搜索栏的附加试图中切换按钮触发的回调