"IOS" uisearchbar background transparent, remove background, customize background

Source: Internet
Author: User

Set the background color of Uisearchbar under ios6,ios7,ios7.1

iOS system upgrade to 7.1, the original in 7.0 display normal Uisearchbar Now there is a problem. The reason is because the subview of Uisearchbar has been modified.

1 //Modify the Searchbar style2 3- (void) Changesearchbar {4 5     floatVersion =[[[ Uidevice Currentdevice] systemversion] floatvalue];6 7     if([_searchbar respondstoselector: @selector (Bartintcolor)]) {8 9         floatIosversion7_1 =7.1;Ten  One         if(Version >=iosversion7_1) { A  -             //iOS7.1 -  the[[[[[_searchbar.subviews Objectatindex:0] Subviews] Objectatindex:0] Removefromsuperview]; -  - [_searchbar setbackgroundcolor:[uicolor clearcolor]; -  +         } -  +         Else{//iOS7.0 A  at [_searchbar setbartintcolor:[uicolor clearcolor]; -  - [_searchbar setbackgroundcolor:[uicolor clearcolor]; -  -         } -  in     } -  to     Else { +  -         //iOS7.0 below the  *[[_searchbar.subviews Objectatindex:0] Removefromsuperview]; $ Panax Notoginseng //[_searchbar setbackgroundcolor:[uicolor clearcolor]; -  the[_searchbar setbackgroundcolor:[uicolor colorwithpatternimage:[uiimageimagenamed:@"Searchbarbg.png"]]]; +  A}}

One line of code, minus the background.

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

----------------------------------------------------------------------

Attention:

After removing the background of the search control, a black line appears below, and we're going to remove that black line.

1 cgrect rect = self.searchBar.frame; 2 UIView *lineview = [[UIView alloc]initwithframe:cgrectmake (0, rect.size.height-22 )]; 3 lineview.backgroundcolor = [Uicolor whitecolor]; 4 [Self.searchbar Addsubview:lineview];

1 /*uisearchbar background Transparent, background removed, custom background*/2 3Seachbar=[[Uisearchbar alloc] init];4 5  6 7 //Modify the search box background8 9Seachbar.backgroundcolor=[Uicolor Clearcolor];Ten  One //Remove the search box background A  - //1. -  the[[Searchbar.subviews Objectatindex:0]removefromsuperview]; -  - //2. -  +  for(UIView *subviewinchseachbar.subviews) -  + {   A  at if([Subview iskindofclass:nsclassfromstring (@"Uisearchbarbackground")]) -  - {   -  - [Subview Removefromsuperview];  -  in  Break;  -  to }   +  - }  the  * //3 Customizing Backgrounds $ Panax NotoginsengUiimageview *imageview = [[Uiimageview alloc] initwithimage:[uiimage imagenamed:@"40-di.png"]]; -  the[Mysearchbar Insertsubview:imageview Atindex:1]; +  A [ImageView release]; the  + //4 Hide Search button when entering search text, display when empty -  $-(BOOL) searchbarshouldbeginediting: (Uisearchbar *) Searchbar { $  -Searchbar.showsscopebar =YES;  -  the [Searchbar SizeToFit];  - Wuyi [Searchbar Setshowscancelbutton:yes Animated:yes];  the  - returnYES;  Wu  - }   About  $-(BOOL) searchbarshouldendediting: (Uisearchbar *) Searchbar { -  -Searchbar.showsscopebar =NO;  -  A [Searchbar SizeToFit];  +  the [Searchbar setshowscancelbutton:no Animated:yes];  -  $ returnYES;  the  the }   the  the //Change Search button text -  in //change uisearchbar Cancel button font the  the  for(IDCcinch[Searchbar subviews]) About  the     { the  the if([CC Iskindofclass:[uibuttonclass]]) +  -         { the BayiUIButton *btn = (UIButton *) cc; the  the[BTN Settitle:@"Search"Forstate:uicontrolstatenormal]; -  -         } the  the}

"IOS" uisearchbar background transparent, remove background, customize background

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.