Basic usage collation of Uisearchbar Search bar components in IOS app development _ios

Source: Internet
Author: User

Basic properties

Copy Code code as follows:

@UISearchBar search = [[Uisearchbar alloc]initwithframe:cgrectmake (0,44,320,120)];

Pragma mark-Basic settings

Copy Code code as follows:

Control style default--0 white, 1 is black style

/*
Uibarstyledefault = 0,
Uibarstyleblack = 1,
Search.barstyle =uibarstyledefault;
/*

Uisearchbarstyledefault,
Currently Uisearchbarstyleprominent

Uisearchbarstyleprominent,//Used my Mail, Messages and Contacts (provides no default background color or image but would d Isplay one if customized as such system offers invalid colors and pictures, custom effective)

Uisearchbarstyleminimal//used by Calendar, Notes and Music

*/

Search.searchbarstyle =uisearchbarstyledefault;

The text displayed above the control

Search.text =@ "HMT";

A single line of text displayed at the top, usually as a hint line

Search.prompt =@ "DOTA";

Translucent hint text, enter search content disappear

Search.placeholder =@ "Please enter the words to search";

Bar color (with gradient effect) Search bar flashing bar and selection bar border, Cancel button and selection bar when selected will become the color set

Search.tintcolor = [Uicolor Redcolor];

In addition to the Search bar box, it is like sticking a blank color map of the search bar, do not affect the color of any other settings

Search.bartintcolor = [Uicolor Whitecolor];

Specifies whether the control will have a perspective effect

Search.translucent =yes;

Set the automatic capitalization in what case

/*

Uitextautocapitalizationtypenone,//Never capitalize unless you click Capitalization

Uitextautocapitalizationtypewords,//in words to distinguish, each word first letter capital

Uitextautocapitalizationtypesentences,//to differentiate by sentence

Uitextautocapitalizationtypeallcharacters,//all letters all uppercase

*/

Search.autocapitalizationtype =uitextautocapitalizationtypenone;

Automatic correction style for text objects (amount, I don't know what to use)

/*

Uitextautocorrectiontypedefault,

Uitextautocorrectiontypeno,

Uitextautocorrectiontypeyes,

*/

Search.autocorrectiontype =uitextautocorrectiontypeno;

The style of the keyboard (specific reference to the article UITableView detailed explanation (i))

Search.keyboardtype =uikeyboardtypenumberpad;


pragma mark-Set the right button icon for the Search bar (Uisearchbaricon)
Copy Code code as follows:

Whether to display a book button on the right side of the control

Search.showsbookmarkbutton =yes;

Show Cancel button (static)

Search.showscancelbutton = YES;

Show Cancel button (with animation effect)

[Search Setshowscancelbutton:yes Animated:yes];

Whether to display the search results button on the right side of the control (the shape is a circle with a downward arrow in it)

Search.showssearchresultsbutton =yes;

Whether the search Results button is selected

Search.showssearchresultsbutton =yes;

Set the right end of the control to display the search results button---Replace the available pictures

[Search Setimage:[uiimage imagenamed:@ "qiyi.png"]forsearchbaricon:uisearchbariconresultslist state: UIControlStateNormal];


pragma mark-Search bar Bottom selection bar
Copy Code code as follows:

The selection bar in the lower part of the search bar, and the contents of the array are the button headings

Search.scopebuttontitles = [Nsarray arraywithobjects:@ "IOS", @ "Android", @ "IPhone", nil];

Enter the index of the default selection bar button at the bottom of the search bar (that is, which selection bar appears first)

Search.selectedscopebuttonindex = 2;

Controls whether the selection bar in the bottom of the search bar is displayed (if shown, modify the search frame, not shown 80 is enough)

Search.showsscopebar =yes;


pragma mark-Set the control picture
Copy Code code as follows:

Set the control background picture

Search.backgroundimage = [UIImage imagenamed:@ "Qiyi.png"];

Set the bottom of the search bar background picture

Search.scopebarbackgroundimage = [UIImage imagenamed:@ "Qiyi.png"];


pragma mark-Agreement uisearchbardelegate

(not explained, see name, already very obvious)

Copy Code code as follows:

@ Edit Text

When Uisearchbar gets the focus and starts editing, execute the method

(BOOL) Searchbarshouldbeginediting: (Uisearchbar *) Searchbar; Return NO to not become-a-responder

(void) Searchbartextdidbeginediting: (Uisearchbar *) searchbar{//Called when text starts editing

[Searchbar Setshowscancelbutton:yes Animated:yes]; Animated Display Cancel button

}

(BOOL) Searchbarshouldendediting: (Uisearchbar *) Searchbar; Return NO to not resign-a-responder

(void) Searchbartextdidendediting: (Uisearchbar *) Searchbar; Called when text ends editing

(void) Searchbar: (Uisearchbar *) Searchbar textdidchange: (NSString *) searchtext{//called when text changes (including CL Ear

@ When the search content changes, execute the method. Useful, real time search can be implemented

}


Copy Code code as follows:

(BOOL) Searchbar: (Uisearchbar *) Searchbar Shouldchangetextinrange: (nsrange) Range Replacementtext: (NSString *) TextNS                 _available_ios (3_0); Called before text changes
@ button click

(void) searchbarsearchbuttonclicked: (Uisearchbar *) Searchbar; Called when keyboard search button pressed

(void) searchbarbookmarkbuttonclicked: (Uisearchbar *) Searchbar; Called when Bookmark button pressed

(void) searchbarcancelbuttonclicked: (Uisearchbar *) searchbar{//Called when Cancel button pressed

[Searchbar Setshowscancelbutton:no Animated:no]; Cancel Button Recycle

[Searchbar Resignfirstresponder]; Cancel first Response value, keyboard recycle, end of search

}

(void) searchbarresultslistbuttonclicked: (Uisearchbar *) Searchbarns_available_ios (3_2);//called When search results Button pressed

(void) Searchbar: (Uisearchbar *) Searchbar Selectedscopebuttonindexdidchange: (Nsinteger) Selectedscopens_available_ IOS (3_0);

Data Brush Select class: Nspredicate

Copy Code code as follows:

@ assume: Nsarray array = [[Nsarray alloc]initwithobjects:@ ' Luna ', @ "Moon", @ "", @ "Lion", @ "Coco", nil];

The processing of data occurs mainly in this method

(void) Searchbar: (Uisearchbar *) Searchbar textdidchange: (NSString *) searchtext{

Method One: ([c] case-insensitive [d] does not distinguish between pronounced symbols, that is, no accent mark [CD] is neither case sensitive nor distinguishes the pronunciation symbol. )

nspredicate * predicate = [nspredicate predicatewithformat:@ "SELF CONTAINS [CD]%@", SearchText];

Array provides a quick traversal, the type returned is Nsarray

NSLog (@ "%@", [_array filteredarrayusingpredicate:predicate]);

Method Two:

for (int i = 0; I count); i++) {

if ([predicate evaluatewithobject:[_array Objectatindex:i]]) {

NSLog (@ "%@", [arrayobjectatindex:i]);

}

}

}

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.