很長一段時間以來,我一直試圖無效地刪除我的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