2

I am new in iphone, i want to change the search bar background to clear color how to change it to clear color. My code is:

UISearchBar *mySearchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(10, 550, 330, 42)]; mySearchBar.delegate = self; mySearchBar.showsCancelButton = YES; mySearchBar.placeholder=@"Search here.."; mySearchBar.tintColor=[UIColor clearColor]; [self.view addSubview:mySearchBar]; 

Thanks in Advance:

4 Answers 4

4

Because search bar have a default view and we remove this view then background color is clear

for (UIView *subview in mySearchBar.subviews) {     if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {         [subview removeFromSuperview];         break;     } }   
Sign up to request clarification or add additional context in comments.

Comments

0

you can set using tint color, try to set tint color as per ur background color.

mySearchBar.tintColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0]; 

Comments

0
mySearchBar.backgroundColor = [UIColor clearColor]; 

Instead of setting the tintColor set the backgroundColor of the searchbar.

Comments

0

in ios 7 i did something like this.

if (self.searchDisplayController.searchBar.subviews.count >= 1) { for (UIView *subview in [[self.searchDisplayController.searchBar.subviews objectAtIndex:0] subviews]) { if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) { [subview removeFromSuperview]; break; } } } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.