Basic uisearchbar operations-Change Background, button text, etc.

Source: Internet
Author: User

Seachbar = [[uisearchbar alloc] init];

// Modify the background of the search box

Seachbar. backgroundcolor = [uicolor clearcolor];

// Remove the background from the search box

// 1.

[[Searchbar. subviews objectatindex: 0] removefromsuperview];

// 2.

For (uiview * subview in seachbar. subviews)

{

If ([subview iskindofclass: nsclassfromstring (@ "uisearchbarbackground")])

{

[Subview removefromsuperview];

Break;

}

}

// 3 custom background

Uiimageview * imageview = [[uiimageview alloc] initwithimage: [uiimage imagenamed: @ "40-di.png"];

[Mysearchbar insertsubview: imageview atindex: 1];

[Imageview release];

// 4 hide the search button when you enter the search text.

-(Bool) searchbarshouldbeginediting :( uisearchbar *) searchbar {

Searchbar. showsscopebar = yes;

[Searchbar sizetofit];

[Searchbar setshowscancelbutton: Yes animated: Yes];

Return yes;

}

-(Bool) searchbarshouldendediting :( uisearchbar *) searchbar {

Searchbar. showsscopebar = no;

[Searchbar sizetofit];

[Searchbar setshowscancelbutton: No animated: Yes];

Return yes;

}

// Change the search button text

// Change the uisearchbar cancel button font

For (id cc in [searchbar subviews])

{

If ([CC iskindofclass: [uibutton class])

{

Uibutton * BTN = (uibutton *) CC;

[BTN settitle: @ "Search" forstate: uicontrolstatenormal];

}

}

From: http://286725277.blog.163.com/blog/static/126728586201182295854561/

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.