How to remove the extra black line beneath UISearchBar?

女生的网名这么多〃 提交于 2019-12-23 07:20:36

问题


After setting the tint of a UISearchBar to White:

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

How can I remove the black line?


回答1:


Just a tweak...

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



回答2:


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];
}



回答3:


searchBar.backgroundImage = [UIImage new];

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



来源:https://stackoverflow.com/questions/8676320/how-to-remove-the-extra-black-line-beneath-uisearchbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!