The dependency of AUSearchBar is as follows:
AUSearchBar is a search bar control of mPaaS.
It supports the following styles:
AUSearchBarStyleNormal
: search bar with a Cancel button, for example, search bar on the homepage for global searchAUSearchBarStyleDetail
: search bar with a Cancel button and a back icon, for example, search bar on a level-2 page for global search
Sample images
Dependency
The dependency of AUSearchBar is as follows:
AntUI(iOS)
1.0.0.161108003457
APCommonUI(iOS)
1.2.0.161108102201
API description
@class AUSearchBar;
@protocol AUSearchBarDelegate <NSObject>
@optional
#pragma mark - Proxy methods corresponding to UITextField.
//
- (BOOL)searchBarTextShouldBeginEditing:(AUSearchBar *)searchBar;
//
- (BOOL)searchBarTextShouldEndEditing:(AUSearchBar *)searchBar;
// Called when text starts editing.
- (void)searchBarTextDidBeginEditing:(AUSearchBar *)searchBar;
// Called when text ends editing.
- (void)searchBarTextDidEndEditing:(AUSearchBar *)searchBar;
// Called when text changes (including clear).
- (void)searchBar:(AUSearchBar *)searchBar textDidChange:(NSString *)searchText;
// Called before text changes.
- (BOOL)searchBar:(AUSearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text;
- (BOOL)searchBarShouldClear:(AUSearchBar *)searchBar;
#pragma mark - Other proxy methods.
// Called when the search icon is clicked.
- (void)searchBarSearchButtonClicked:(AUSearchBar *)searchBar;
// Called when the Cancel button is clicked.
- (void)searchBarCancelButtonClicked:(AUSearchBar *) searchBar;
// Called when the back icon is clicked (valid for the AUSearchBarStyleDetail style).
- (void)searchBarBackButtonClicked:(AUSearchBar *)searchBar;
// Called when the voice icon is clicked (valid when shouldShowVoiceButton is set to YES).
- (void)searchBarOpenVoiceAssister:(AUSearchBar *)searchBar;
@end
typedef NS_ENUM(NSUInteger, AUSearchBarStyle) {
AUSearchBarStyleNormal = 0,//normal.
AUSearchBarStyleDetail, //has back Button
};
/**
The search bar control. (By default, the width is the same as that of the screen, and the height is 44.)
*/
@interface AUSearchBar : UIView
@property (nonatomic, strong) NSString *text; // The search box text.
@property (nonatomic, assign) BOOL isSupportHanziMode; // Whether to support search while input. Default value: YES.
@property (nonatomic, assign) AUSearchBarStyle style; // The style of the search box.
@property (nonatomic, assign) BOOL shouldShowVoiceButton; // Whether to display the Voice button. Default value: NO.
@property (nonatomic, strong, readonly) UITextField *searchTextField; // The search box.
@property (nonatomic, weak) id<AUSearchBarDelegate> delegate;
/**
The initialization method.
@param style The search bar style.
@return Return an AUSearchBar instance.
*/
- (instancetype)initWithStyle:(AUSearchBarStyle)style;
@end
Code sample
Add to the navigation bar
AUSearchBar *searchBar = [[AUSearchBar alloc] initWithStyle:AUSearchBarStyleNormal];
searchBar.searchTextField.placeholder = @"The search bar style (AUSearchBarStyleNormal)";
searchBar.delegate = self;
searchBar.isSupportHanziMode = YES;
searchBar.shouldShowVoiceButton = YES;
self.navigationItem.titleView = searchBar;
self.navigationItem.leftBarButtonItem = nil; // Add no button to the left of the search bar.
self.navigationItem.rightBarButtonItem = nil; // Add no button to the right of the search bar.
self.navigationItem.hidesBackButton = YES; // Hide the back icon.
Add to a normal view
searchBar = [[AUSearchBar alloc] initWithStyle:AUSearchBarStyleDetail];
searchBar.searchTextField.placeholder = @"The search bar style (AUSearchBarStyleDetail)";
searchBar.delegate = self;
searchBar.isSupportHanziMode = YES;
searchBar.shouldShowVoiceButton = YES;
[self.view addSubview:searchBar];