简体   繁体   English

如何删除UISearchBar下面的额外黑线?

[英]How to remove the extra black line beneath UISearchBar?

After setting the tint of a UISearchBar to White: UISearchBar的色调设置为白色后:

在此输入图像描述

There is an extra black line between the search box and the table: 搜索框和表格之间有一条额外的黑线:

在此输入图像描述

How can I remove the black line? 如何删除黑线?

Just a tweak... 只是一个调整......

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

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. 我意识到Legolas的答案是陈旧的 - 但是我偶然发现了同样的问题,现在看起来似乎没有一个borderColor是一个特殊的视图,充当阴影,创造了这种效果。

The only way of fixing this is to search for a view called "_UISearchBarShadowView" and hide it. 解决此问题的唯一方法是搜索名为“_UISearchBarShadowView”的视图并将其隐藏。

It is a subview of a subview of searchDisplayController.searchResultsTableView and only exists after typing a character into the search bar. 它是searchDisplayController.searchResultsTableView子视图的子视图,仅在搜索栏中键入字符后才存在。 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) (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]; searchBar.backgroundImage = [UIImage new];

See the explanation from 'theMonster' here: https://stackoverflow.com/a/25275021/1751266 请参阅“theMonster”中的解释: https ://stackoverflow.com/a/25275021/1751266

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM