Can I remove background or borders from UISearchBar?

I would like to get something like this:

enter image description here

But I was not able to remove the original background (I am using iOS5). However, it seems Apple did this:

enter image description here

How can I create what I want? Or is there no choice, and the only alternative I have is to configure a UITextField?

Thanks for the suggestions and ideas!

EDIT: after the first answer, this is what I got:

enter image description here

Anyone how I can remove the white inner background without making all components translucent by changing the alpha value? BTW, can I change the white color to black?

+5
source share
3 answers

Try this code, it worked for me

for (id img in yourSearchBar.subviews) {
        if ([img isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
           [img removeFromSuperview];    
        }
    }

yourSearchBar - , , for UISearchBar

+7

. UISearchBar,

UIImage *searchBg = [UIImage imageNamed:@"search_bar.png"];
[searchBar setBackgroundImage:searchBg];

, ( - , AppDelegate, , , .

UIImage *searchBg = [UIImage imageNamed:@"search_bar.png"];
[[UISearchBar appearance] setBackgroundImage:searchBg];

: , , :

searchBar:

[searchBar setSearchFieldBackgroundImage:searchBg forState:UIControlStateNormal];

UISearchBars:

[[UISearchBar appearance] setSearchFieldBackgroundImage:searchBg forState:UIControlStateNormal];

, .

+6

iOS 7 :

searchBar.barTintColor = [UIColor clearColor];
+1

All Articles