很长一段时间以来,我一直试图删除我的UISearchBar上的一条有害的线路,但没有效果。它在亮的背景上看上去很暗,在暗的背景上看起来很暗:


我看了一下this question,但它与分隔符或拉式刷新无关。当我最终决定放弃并寻求帮助时,我又开始四处张望,找到了一个简单得令人眼花缭乱的解决方案(尽管可能不是完全直观的),所以我想,如果其他人面临同样的问题,我会分享它。我将搜索栏配置为:
// 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"]]];根据this post's的建议,我尝试在上面绘图,但它似乎仍然呈现在线以下。
CGRect rect = self.searchBar.frame;
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, rect.size.width, 2)];
lineView.backgroundColor = [UIColor redColor];请参见我的红色“掩盖”行的示例:

发布于 2013-03-13 15:14:14
我不认为会成功,但这是有意义的,因为必须为掩盖视图设置一个负y值。
searchBar.clipsToBounds = YES;发布于 2016-04-25 15:09:47
希望这能帮上忙:
self.searchBar.layer.borderColor = Color.CGColor;
self.searchBar.layer.borderWidth = 1;您可以在searchBar中找到searchController属性
发布于 2017-01-20 09:15:09
在我的例子中,我在代码中创建了一个UISearchBar,并将它作为正确的条形按钮项放置在导航栏中。将背景图像设置为空图像删除了1像素线。
searchBar.backgroundImage = UIImage()https://stackoverflow.com/questions/15370070
复制相似问题