For quite some time, I had been trying to no avail to remove a pernicious line above my UISearchBar. It appears dark on a light background or light on a dark background:
I looked at this question, but it had nothing to do with the separator or pull-to-refresh. When I finally decided to give up and ask for help, I started poking around again and found a blindingly simple (though perhaps not entirely intuitive) solution, so I thought I'd share it in case others are facing the same issue. I configure the search bar as follows:
// I tried this drawing method
[self.searchBar setBackgroundImage:[[UIImage imageNamed:@"linen_bg_bar.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]];
// and this one.
[self.searchBar setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"linen_bg_bar.png"]]];
// Same problem either way.
[self.searchBar setPlaceholder:NSLocalizedString(@"Filter", @"placeholder text in the search bar")];
[self.searchBar setSearchFieldBackgroundImage:[[UIImage imageNamed:@"linen_textfield_search.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(16, 16, 16, 16)] forState:UIControlStateNormal];
[self.searchBar setImage:[UIImage imageNamed:@"linen_icon_search.png"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
self.table.tableHeaderView = self.searchBar;
[self.table setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"linen_bg_dark.png"]]];
Per this post's suggestion, I tried drawing on top of it, but it seemed the drawing still got rendered below the line.
CGRect rect = self.searchBar.frame;
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, rect.size.width, 2)];
lineView.backgroundColor = [UIColor redColor];
See the example with my red "cover-up" line:
I'm not sure this will work, but it makes sense, based on having to set a negative y value for the cover-up view.
searchBar.clipsToBounds = YES;
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