triveni
triveni

Reputation: 377

Is it possible to remove UISearchBar's tint image?

i have to hide searchbar tint. i write foll0wing code

UISearchBar *searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 15, 270, 15)];
searchBar.delegate = self;
searchBar.barStyle = UISegmentedControlStylePlain;
searchBar.placeholder =@"search";
searchBar.tintColor=[UIColor clearColor];
[imageview addSubview:searchBar];

here search bar add on imageview. i want to hide tint side but bydeaflt it comes .i also chage the color to tint color but it not work.is anybody have idea of removing or hide tint on searchbar .Thanks

Upvotes: 1

Views: 2285

Answers (4)

Ronald Randon
Ronald Randon

Reputation: 1191

Hope this helps.

[searchBar setBackgroundImage:[UIImage new]];

Will also work in iOS 7.1

Upvotes: 4

Dhawal
Dhawal

Reputation: 185

I have used this code. It completely removed the tint around the search text bar.

for (id v in [self.search subviews]) {
        if (![v isKindOfClass:NSClassFromString(@"UISearchBarTextField")]) {
            [v setAlpha:0.0f];
            [v setHidden:YES];
        }
        else {
            [v setBackgroundColor:[UIColor clearColor]];
        }

    }

Upvotes: 2

tierfour
tierfour

Reputation: 682

Here's how I customized the UISearchBar

if ([[[searchBar subviews] objectAtIndex:0] isKindOfClass:[UIImageView class]]){
    [[[searchBar subviews] objectAtIndex:0] removeFromSuperview];
}

This removes the background bar style.

You can then add any custom subview you want.

Upvotes: 1

John Carter
John Carter

Reputation: 2056

Try this

[searchBar setTranslucent:YES];

Also, don't set the tintColor when using translucent

Upvotes: 0

Related Questions