很长一段时间以来,我一直试图删除 UISearchBar 上方的有害行,但无济于事。它在浅色背景上看起来很暗或在深色背景上看起来很亮:
我看了这个问题,但它与分隔符或下拉刷新无关。当我最终决定放弃并寻求帮助时,我再次开始四处寻找并找到了一个非常简单(尽管可能不完全直观)的解决方案,所以我想我会分享它以防其他人面临同样的问题。我将搜索栏配置如下:
// 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"]]];
根据这篇文章的建议,我尝试在其上绘图,但似乎绘图仍被渲染到线以下。
CGRect rect = self.searchBar.frame;
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, rect.size.width, 2)];
lineView.backgroundColor = [UIColor redColor];
请参阅带有我的红色“掩盖”行的示例: