IOS development-UISearchBar of the UIKit control (search bar) and uikituisearchbar

Source: Internet
Author: User

IOS development-UISearchBar of the UIKit control (search bar) and uikituisearchbar
Today, you need to use the search control because of your needs. You have never used this control before, so I went to Baidu and found a complete article. Thank you for this author.

However, I have not found any attribute or method for changing the font size. Please let me know. Thank you!

Address: http://my.oschina.net/u/2340880/blog/509756

Initialization: UISearchBar inherits from UIView. We can create a searchBar like creating a View.
1 UISearchBar *bar = [[UISearchBar alloc]initWithFrame:CGRectMake(20, 100, 250, 40)];2 [self.view addSubview:bar];
1 // you can set the searchBar search 2 @ property (nonatomic) UIBarStyle barStyle; 3 // enumeration: 4 typedef NS_ENUM (NSInteger, UIBarStyle) {5 UIBarStyleDefault = 0, // The default style is the white search box. The extra background is gray 6 UIBarStyleBlack = 1. // The Black style is displayed. The black search box 7 // The following two enumerations are disabled, same as the black style 8 UIBarStyleBlackOpaque = 1, // Deprecated. use UIBarStyleBlack 9 UIBarStyleBlackTranslucent = 2, // Deprecated. use UIBarStyleBlack and set the translucent property to YES10 };

Set text in the search box

1 @property(nonatomic,copy) NSString *text; 

The official explanation of this attribute is to display a line of text at the top of the search box, which is actually the background text. Description:

1 @property(nonatomic,copy) NSString *prompt; 
1 bar. prompt = @ "search box"; 2 bar. text = @ "321111111111111111111111111"

The effect is as follows:

 

It is the same as placeholder of other text input controls and disappears when the text is entered.

1 @property(nonatomic,copy) NSString *placeholder;  

Whether to display a book button on the right of the search box. The default value is NO. The effect of YES is as follows:

1 @property(nonatomic) BOOL showsBookmarkButton; 

Whether to display the cancel button. The default value is NO. The effect of YES is as follows:

1 @property(nonatomic) BOOL showsCancelButton;

Whether to display the search result button. The default value is "NO". The effect of "YES" is as follows:

1 @property(nonatomic) BOOL showsSearchResultsButton;

Select the search result button

1 @property(nonatomic, getter=isSearchResultsButtonSelected) BOOL searchResultsButtonSelected ;

Set the show cancel button

1 - (void)setShowsCancelButton:(BOOL)showsCancelButton animated:(BOOL)animated;

Setting this color value will affect the color of the cursor in the search box.

1 @property(nonatomic,retain) UIColor *tintColor;

Setting this color will affect 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 enumerated values are as follows:

1 typedef NS_ENUM (NSUInteger, UISearchBarStyle) {2 UISearchBarStyleDefault, // currently adjust background, // Display Background 4 UISearchBarStyleMinimal // Do Not Display Background 5} partition (7_0 );

 

Set to translucent

1 @property(nonatomic,assign,getter=isTranslucent) BOOL translucent;

Whether to display the attachment selection button view in the search bar. To display this view, first set this attribute to YES, and then add a button to the button array to use the following attribute:

1 @property(nonatomic) BOOL showsScopeBar ;

Set the button title for the select button View

1 @property(nonatomic,copy) NSArray *scopeButtonTitles ;2 3 @property(nonatomic) NSInteger selectedScopeButtonIndex;

Set a default selected button

bar = [[UISearchBar alloc]initWithFrame:CGRectMake(20, 100, 250, 200)];bar.showsScopeBar=YES;bar.scopeButtonTitles = @[@"12",@"2",@"3",@"4"];

Secondary view of the keyboard

1 @property (nonatomic, readwrite, retain) UIView *inputAccessoryView;

Set the background pattern of the search box

1 @property(nonatomic,retain) UIImage *backgroundImage;

Set the background pattern of the affiliated selection button View

1 @property(nonatomic,retain) UIImage *scopeBarBackgroundImage;

This method can be used to set and obtain the background pattern of the search box in a certain state enumeration.

-(Void) setBackgroundImage :( UIImage *) backgroundImage forBarPosition :( UIBarPosition) barPosition barMetrics :( UIBarMetrics) barMetrics;

-(UIImage *) backgroundImageForBarPosition :( UIBarPosition) barPosition barMetrics :( UIBarMetrics) barMetrics

This method is used to set and obtain the background pattern of TextField in the search box.

-(Void) setSearchFieldBackgroundImage :( UIImage *) backgroundImage forState :( UIControlState) state;

-(UIImage *) searchFieldBackgroundImageForState :( UIControlState) state;

This method is used to obtain and set the icon image pattern in the search bar.

-(Void) setImage :( UIImage *) iconImage forSearchBarIcon :( UISearchBarIcon) icon state :( UIControlState) state;

-(UIImage *) imageForSearchBarIcon :( UISearchBarIcon) icon state :( UIControlState) state;

This method is used to set and obtain the background pattern of the additional selection button view in the search box.

-(Void) setScopeBarButtonBackgroundImage :( UIImage *) backgroundImage forState :( UIControlState) state;

-(UIImage *) scopeBarButtonBackgroundImageForState :( UIControlState) state;

This method is used to obtain and set the pattern of the switch 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 method is used to set and retrieve the font attribute Dictionary of the title Text of the switch button.

-(Void) setScopeBarButtonTitleTextAttributes :( NSDictionary *) attributes forState :( UIControlState) state;

-(NSDictionary *) scopeBarButtonTitleTextAttributesForState :( UIControlState) state;

Position offset of search text in the search box

@ Property (nonatomic) UIOffset searchFieldBackgroundPositionAdjustment;

Position offset of textfield in the search box

@ Property (nonatomic) UIOffset searchTextPositionAdjustment;

Set the position offset of the image in the search bar

-(Void) setPositionAdjustment :( UIOffset) adjustment forSearchBarIcon :( UISearchBarIcon) icon;

-(UIOffset) positionAdjustmentForSearchBarIcon :( UISearchBarIcon) icon;

The image enumeration is as follows:

Typedef NS_ENUM (NSInteger, UISearchBarIcon) {UISearchBarIconSearch, // search icon UISearchBarIconClear, // clear icon UISearchBarIconBookmark, // book icon marker, // result list icon };

The following are some proxy methods for the search box control:

Callback when editing is to begin. If NO is returned, it cannot be edited.

-(BOOL) searchBarShouldBeginEditing :( UISearchBar *) searchBar;

Callback when editing is started

-(Void) searchBarTextDidBeginEditing :( UISearchBar *) searchBar;

Callback when editing is to end

-(BOOL) searchBarShouldEndEditing :( UISearchBar *) searchBar;

Callback with edited end

-(Void) searchBarTextDidEndEditing :( UISearchBar *) searchBar;

Callback for editing text changes

-(Void) searchBar :( UISearchBar *) searchBar textDidChange :( NSString *) searchText;

The callback before the edited text changes. If NO is returned, the new edited text cannot be added.

-(BOOL) searchBar :( UISearchBar *) searchBar shouldChangeTextInRange :( nsange) range replacementText :( NSString *) text;

Search button click callback

-(Void) searchBarSearchButtonClicked :( UISearchBar *) searchBar;

Book button click callback

-(Void) searchBarBookmarkButtonClicked :( UISearchBar *) searchBar;

Call back when the cancel button is clicked

-(Void) searchBarCancelButtonClicked :( UISearchBar *) searchBar;

Callback for clicking the search result button

-(Void) searchBarResultsListButtonClicked :( UISearchBar *) searchBar;

Callback triggered by the switch button in the additional view of the search bar

-(Void) searchBar :( UISearchBar *) searchBar selectedScopeButtonIndexDidChange :( NSInteger) selectedschange;

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.