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
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.
You can add a UISearchBar as you would with any other control by dragging one to your view controller in interface builder or by programmatically adding it. The delegate property of search bar must be set to an object that implements UISearchBarDelegate.
Set Search Style = minimal in Search Bar properties in IB
Or
Swift: searchBar.searchBarStyle = UISearchBarStyleMinimal; Swift 3: searchBar.searchBarStyle = .minimal;
Setting searchBarStyle to UISearchBarStyleMinimal messed up my color setup, so doing this instead fixed the issue.
[self.searchField setBackgroundImage:[[UIImage alloc]init]];
For those looking for this option in Swift 4:
searchField.setBackgroundImage(UIImage(), for: .any, barMetrics: UIBarMetrics.default)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With