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/