Initialize: Uisearchbar inherits from UIView, we can create a searchbar like a view
1 uisearchbar *bar = [[Uisearchbar alloc]initwithframe:cgrectmake] )]; 2 [Self.view Addsubview:bar];
1 //This property allows you to set the search for Searchbar2 @property (nonatomic) Uibarstyle Barstyle;3 //The enumeration is as follows:4 typedef ns_enum (Nsinteger, Uibarstyle) {5Uibarstyledefault =0,//Default Style white search box, multi-out background is gray6Uibarstyleblack =1,//Black-style, black search box7 //the following two enumerations have been disabled, the same as black style8Uibarstyleblackopaque =1,//Deprecated. Use Uibarstyleblack9Uibarstyleblacktranslucent =2,//Deprecated. Use Uibarstyleblack and set the translucent property to YESTen};
Set the text in the search box
1
The official explanation of this property is to display a line of text at the top of the search box, which is actually the background text, stating:
1
1 @" Search Box " ; 2 bar.text=@ "321111111111111111111111111"
The effect is as follows:
Same as placeholder of other text input controls, disappears when text is entered
1 @property (nonatomic,copy) NSString *placeholder;
Whether to display a book's button to the right of the search box, the default is No,yes as follows:
1
If the Cancel button is displayed, the default is No,yes as follows:
1 @property (nonatomic) BOOL Showscancelbutton;
If the search results button is displayed, the default No,yes effect is as follows:
1 @property (nonatomic) BOOL Showssearchresultsbutton;
Set the search Results button to the selected state
1 @property (nonatomic, getter=issearchresultsbuttonselected) BOOL searchresultsbuttonselected;
Set Display Cancel button
1 -(void) Setshowscancelbutton: (BOOL) Showscancelbutton animated: (bool) animated;
Setting this color value affects the color of the cursor in the search box
1 @property (nonatomic,retain) Uicolor *tintcolor;
Setting this color affects the background color of the search box
1 @property (nonatomic,retain) Uicolor *bartintcolor;
Set the overall style of the search box
1 @property (nonatomic) Uisearchbarstyle Searchbarstyle;
The enumeration is as follows:
1 typedef ns_enum (Nsuinteger, Uisearchbarstyle) {2 Uisearchbarstyledefault, // currently uisearchbarstyleprominent3 Uisearchbarstyleprominent, // display background 4 uisearchbarstyleminimal // do not show background 5 } ns_enum_available_ios (7_0);
Set whether translucent
1 @property (nonatomic,assign,getter=istranslucent) BOOL translucent;
Whether to display the Attachment selection button view of the search bar, to display this view, first set this property to Yes, and then add a button to the button array, using this property:
1 @property (nonatomic) BOOL Showsscopebar;
Set button title for Select button View
1 @property (nonatomic,copy) nsarray *scopebuttontitles;23 @property (nonatomic) Nsinteger Selectedscopebuttonindex;
Set a default Check button
bar = [[Uisearchbar alloc]initwithframe:cgrectmake]; Bar.showsscopebar== @[@"2"@ "@" @ "3",@ "4"];
Attached view of the keyboard
1 @property (nonatomic, ReadWrite, retain) UIView *inputaccessoryview;
Set the background pattern for the search box
1 @property (nonatomic,retain) UIImage *backgroundimage;
Sets the background pattern of the secondary selection button view
1 @property (nonatomic,retain) UIImage *scopebarbackgroundimage;
This pair of methods can set and get the background pattern of the search box under a State enumeration
-(void) SetBackgroundImage: (UIImage *) backgroundimage forbarposition: (uibarposition) barposition barmetrics: ( Uibarmetrics) Barmetrics;
-(UIImage *) Backgroundimageforbarposition: (uibarposition) barposition barmetrics: (uibarmetrics) BarMetrics
This pair of methods is used to set and get the background pattern of TextField in the search box
-(void) Setsearchfieldbackgroundimage: (UIImage *) backgroundimage forstate: (uicontrolstate) state;
-(UIImage *) Searchfieldbackgroundimageforstate: (uicontrolstate) state;
This pair of methods is used to get and set the pattern of the search bar icon picture
-(void) SetImage: (UIImage *) iconimage Forsearchbaricon: (uisearchbaricon) icon State: (uicontrolstate) state;
-(UIImage *) Imageforsearchbaricon: (Uisearchbaricon) icon State: (uicontrolstate) state;
This pair of methods is used to set and get the background pattern of the search box's additional selection button view
-(void) Setscopebarbuttonbackgroundimage: (UIImage *) backgroundimage forstate: (uicontrolstate) state;
-(UIImage *) Scopebarbuttonbackgroundimageforstate: (uicontrolstate) state;
This pair of methods is used to get and set the pattern of the toggle button in the Additional selection button view
-(void) Setscopebarbuttondividerimage: (UIImage *) dividerimage forleftsegmentstate: (uicontrolstate) leftstate Rightsegmentstate: (uicontrolstate) rightstate;
-(UIImage *) Scopebarbuttondividerimageforleftsegmentstate: (uicontrolstate) leftstate rightsegmentstate: ( Uicontrolstate) Rightstate;
This pair of methods is used to set and get the Font property dictionary for toggle button Caption text
-(void) Setscopebarbuttontitletextattributes: (nsdictionary *) attributes Forstate: (uicontrolstate) state;
-(Nsdictionary *) Scopebarbuttontitletextattributesforstate: (uicontrolstate) state;
The position offset of the search text in the search box
@property (nonatomic) Uioffset searchfieldbackgroundpositionadjustment;
TextField position offset in the search box
@property (nonatomic) Uioffset searchtextpositionadjustment;
Set the position offset of a picture in the search bar
-(void) Setpositionadjustment: (uioffset) Adjustment Forsearchbaricon: (uisearchbaricon) icon;
-(Uioffset) Positionadjustmentforsearchbaricon: (Uisearchbaricon) icon;
The image is enumerated as follows:
typedef ns_enum (Nsinteger, Uisearchbaricon) { // search icon // Clear icon // book icon // result list icon };
Here are some proxy methods for the search box control:
The callback that will start editing, returned as no, cannot be edited
-(BOOL) searchbarshouldbeginediting: (Uisearchbar *) Searchbar;
Callbacks that have started editing
-(void) searchbartextdidbeginediting: (Uisearchbar *) Searchbar;
Callback to end Edit
-(BOOL) searchbarshouldendediting: (Uisearchbar *) Searchbar;
Callback that has finished editing
-(void) searchbartextdidendediting: (Uisearchbar *) Searchbar;
Edit the callback for the text change
-(void) Searchbar: (Uisearchbar *) Searchbar textdidchange: (NSString *) SearchText;
Edit the callback before the text changes, return No to add new editing text
-(BOOL) Searchbar: (Uisearchbar *) Searchbar Shouldchangetextinrange: (nsrange) Range Replacementtext: (NSString *) text;
Callback for Search button click
-(void) searchbarsearchbuttonclicked: (Uisearchbar *) Searchbar;
The callback of the book button click
-(void) searchbarbookmarkbuttonclicked: (Uisearchbar *) Searchbar;
Cancel button click of callback
-(void) searchbarcancelbuttonclicked: (Uisearchbar *) Searchbar;
Callback for the Search results button click
-(void) searchbarresultslistbuttonclicked: (Uisearchbar *) Searchbar;
Callback triggered by toggle button in additional view of the search bar
-(void) Searchbar: (Uisearchbar *) Searchbar Selectedscopebuttonindexdidchange: (Nsinteger) Selectedscope;
iOS Development--uikit Control Uisearchbar (search box)