iEngineer iEngineer - 6 months ago 276
iOS Question

Remove Border of UISearchBar in iOS7

I'm trying to remove border of UISearchBar in iOS 7. In iOS 6 it's working fine. I created the UISearchBar programatically. I tried almost every thing from Stack Overflow and Google.

SearchBar looking right now

SearchBar looking right now

What i want to achieve

What i want to achieve

I tried all these stuffs mentioned below

searchBar.layer.borderWidth = 1;
searchBar.layer.borderColor = [[UIColor whiteColor] CGColor];


and

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


and

for (UIView *sub in self.tableView.tableHeaderView.subviews) {
if ([sub isKindOfClass:[UIImageView class]]) {
sub.hidden = YES;
}
}


but still no success.

Answer

Ok, i found the solution that worked for me by setting the barTintColor of UISearchBar to clearColor

topSearchBar.barTintColor = [UIColor clearColor];

Hope this will help other guys as well.