2015-11-17 36 views
0

我有一個UISearchBar其bartintcolor我已經改變,並取消啓用。這是作爲UIVew的子視圖添加的。每當使搜索欄可見時,它會在其下方顯示一條永不消失的黑線。UIsearchbar在它下面顯示一條永遠不會去的線

我是否錯過了關於UISearchbar外觀或其背景視圖。

dummyview=[[UIView alloc]initWithFrame:CGRectMake(10, 30,self.headerView.frame.size.width-20, 30)]; 
    [dummyview setBackgroundColor:[UIColor redColor]]; 
    [dummyview setClipsToBounds:TRUE]; 
    self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, dummyview.frame.size.width, dummyview.frame.size.height)]; 
    self.searchBar.delegate = (id)self; 
    [self.searchBar setPlaceholder:@"Search"]; 

    self.searchBar.showsCancelButton = YES; 
    _searchBar.barTintColor = [Utilities colorWithHexString:@"3a7ebc"]; 
    [[UIBarButtonItem appearanceWhenContainedIn: [UISearchBar class], nil] setTintColor:[UIColor whiteColor]]; 


    _searchBar.delegate=self; 
    [dummyview addSubview:_searchBar]; 

它給了我這樣的

Black line color just below

如果我改變背景爲本地一個,我得到流離失所的內容。 // _searchBar.barTintColor = [Utilities colorWithHexString:@"3a7ebc"];

enter image description here

我只是不想在搜索欄下方的黑線。

更新時間: 使用 _searchBar.searchBarStyle=UISearchBarStyleMinimal; _searchBar.barStyle=UIBarStyleDefault;

結果在這個enter image description here

所以 終於完成這一切

_searchBar.searchBarStyle=UISearchBarStyleMinimal; _searchBar.barStyle=UIBarStyleDefault; UITextField *searchField=[_searchBar valueForKey:@"_searchField"]; if (searchField) { [searchField setTextColor:[UIColor whiteColor]]; }

+0

你試過[這](http://stackoverflow.com/questions/6868214/remove-the-1px-border-under-uisearchbar) –

+0

我想我試過這些。讓我再嘗試一次。 –

+0

更改搜索欄樣式最小屬性。 –

回答

0

把我的代碼在viewDidLoad中或viewWillAppear中的方法。

searchbar.barTintColor=[UIColor samebgcolor]; 
searchbar.layer.borderWidth = 1; 
searchbar.layer.borderColor = [[UIColor samebgcolor] CGColor]; 

我也會考慮,「我希望這將幫助你」,因爲這是最強的,並希望事情肯定會,一定的幫助。

如果你喜歡我的回答使接受並給予好評我的答案

+0

這是行不通的。已更新我的代碼。 –

+0

你有samebgcolor替換你的背景顏色值並檢查? –