很长一段时间以来,我一直试图无效地删除我的UISearchBar上的有害线。它出现在一个黑暗的背景光背景或光线暗的:线以上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];
见我的红色的“障眼法”行的例子:
完美的作品!但对我来说,这似乎很奇怪,搜索栏在界限之外划出一条线。 – enjayem 2013-03-13 16:17:22
@enjayem我知道。你是否特意将'clipsToBounds'变成了某个地方? – Undo 2013-03-13 19:18:37
不是。我所做的只是设置自定义背景图像。 – enjayem 2013-03-13 20:38:02