10

After setting the tint of a UISearchBar to White:

enter image description here

There is an extra black line between the search box and the table:

enter image description here

How can I remove the black line?

ohho
  • 50,879
  • 75
  • 256
  • 383
  • have you cleared search bar's background ? – Maulik Dec 30 '11 at 05:12
  • `searchBar.backgroundColor = [UIColor clearColor];` does not help. – ohho Dec 30 '11 at 06:17
  • Possible duplicate of [Customize UISearchBar: Trying to get rid of the 1px black line underneath the search bar](http://stackoverflow.com/questions/7620564/customize-uisearchbar-trying-to-get-rid-of-the-1px-black-line-underneath-the-se) – CMash Apr 01 '16 at 11:59

3 Answers3

27

Just a tweak...

searchBar.layer.borderWidth = 1;
searchBar.layer.borderColor = [[UIColor whiteColor] CGColor];
Legolas
  • 12,145
  • 12
  • 79
  • 132
0

I realize Legolas answer is old - but I stumbled upon the same problem, and now it seems there instead of a borderColor is a special view acting as a shadow which creates this effect.

The only way of fixing this is to search for a view called "_UISearchBarShadowView" and hide it.

It is a subview of a subview of searchDisplayController.searchResultsTableView and only exists after typing a character into the search bar. I fixed the problem with the code below.

(getSubviewByClass is a category of UIView I created to loop through views and find subviews by a string)

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {

    [self performSelector:@selector(searchResultsTableShouldChange) withObject:nil afterDelay:0.0001];

}

- (void)searchResultsTableShouldChange {

    [[self.view getSubviewByClass:@"_UISearchBarShadowView"] setHidden:YES];
}
Filibustr
  • 77
  • 8
0

searchBar.backgroundImage = [UIImage new];

See the explanation from 'theMonster' here: https://stackoverflow.com/a/25275021/1751266

Community
  • 1
  • 1
CMash
  • 1,987
  • 22
  • 35