Mohammed
Mohammed

Reputation: 334

How to remove search bar background?

I want to remove search bar background and I have tried the following code in custom search bar subclass:

-(void)didAddSubview:(UIView *)subview
{
    if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
    {
        subview.alpha=0;

    }
}

every thing ok but when click on search bar or cancel search the background color set to black
any one knows how to remove this background color?

Upvotes: 0

Views: 2159

Answers (2)

MadhuP
MadhuP

Reputation: 2019

searchbar.barStyle = UIBarStyleBlackTranslucent;

Hope it helps you

Upvotes: 4

Mihir Das
Mihir Das

Reputation: 478

I used this code in one of my applications to remove the background and added my own background image

[[searchBar.subviews objectAtIndex:0] removeFromSuperview];
     UIImageView *searchImage=[[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 319.0, 44.0)];
    [searchImage setImage:[UIImage imageNamed:@"searchbg.png"]];
    [searchBar insertSubview:searchImage atIndex:1];

This may help you.

Upvotes: 1

Related Questions