2012-08-16 46 views
1

我正在編寫UISearchBar,我已經創建了。下面是我有一個問題是什麼:UISearchBar怪異的線條

http://oi46.tinypic.com/2lo25qu.jpg

我怎樣才能得到這個搜索欄上擺脫這一行的?

的代碼如下:

[self setBackgroundColor:[UIColor clearColor]]; 
[self setBarStyle:UIBarStyleDefault]; 
[self setTintColor:[UIColor whiteColor]]; 
[self setShowsCancelButton:NO]; 
+1

請告訴我們一些相關的代碼來幫助你。 – limon 2012-08-16 21:43:57

+0

這已被問及在這裏解決:[自定義UISearchBar](http://stackoverflow.com/questions/7620564/customize-uisearchbar-trying-to-get-rid-of-1px-black-line-underneath-the-搜索?rq = 1) – SethHB 2012-08-16 23:30:44

回答

0

要設置背景色clearColor。您可以刪除的UISearchBar而不是背景視圖:

for(UIView *view in [searchBar subviews]){ 
    if([view isKindOfClass:NSClassFromString(@"UISearchBarBackground")]){ 
     [view removeFromSuperview]; 
    } 
} 

// in the above code in place of "searchBar" you have to use "self" 
+0

謝謝,工作就像一個魅力。 – kforkarim 2012-09-05 16:28:15

0

您可以在iOS 5以上擺脫線的使用

[[UISearchBar appearance] setSearchFieldBackgroundImage:[UIImage imageNamed:@"someImage.png"]forState:UIControlStateNormal]; 

0

我所做的是改變底層:

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