【发布时间】:2011-12-30 05:01:43
【问题描述】:
将UISearchBar 的色调设置为白色后:
搜索框和表格之间多了一条黑线:
如何去除黑线?
【问题讨论】:
-
你清除了搜索栏的背景吗?
-
searchBar.backgroundColor = [UIColor clearColor];没有帮助。
标签: iphone ios5 uisearchbar
将UISearchBar 的色调设置为白色后:
搜索框和表格之间多了一条黑线:
如何去除黑线?
【问题讨论】:
searchBar.backgroundColor = [UIColor clearColor]; 没有帮助。
标签: iphone ios5 uisearchbar
稍微调整一下……
searchBar.layer.borderWidth = 1;
searchBar.layer.borderColor = [[UIColor whiteColor] CGColor];
【讨论】:
我意识到 Legolas 的答案已经过时了 - 但我偶然发现了同样的问题,现在似乎有一个特殊的视图,而不是一个边框颜色,而是一个充当阴影的特殊视图,它产生了这种效果。
解决此问题的唯一方法是搜索名为“_UISearchBarShadowView”的视图并将其隐藏。
它是searchDisplayController.searchResultsTableView 的子视图的子视图,只有在搜索栏输入字符后才存在。我用下面的代码解决了这个问题。
(getSubviewByClass 是我创建的 UIView 的一个类别,用于遍历视图并通过字符串查找子视图)
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
[self performSelector:@selector(searchResultsTableShouldChange) withObject:nil afterDelay:0.0001];
}
- (void)searchResultsTableShouldChange {
[[self.view getSubviewByClass:@"_UISearchBarShadowView"] setHidden:YES];
}
【讨论】:
searchBar.backgroundImage = [UIImage new];
在此处查看“theMonster”的解释:https://stackoverflow.com/a/25275021/1751266
【讨论】: