2016-04-03 168 views
0

我希望我的導航欄和搜索欄具有相同的顏色。我也想擺脫他們之間的細線,但與第一個相比,這似乎是一個小問題。 的導航欄屬性設置是這樣的:導航欄和搜索控制器

self.navigationController?.navigationBar.barTintColor = ColorHelper.sharedInstance.LightPink() 
    if let navBarFont = UIFont(name: "HelveticaNeue-Light", size: 25.0) { 
     let navBarAttributesDictionary: [String: AnyObject]? = [ 
      NSForegroundColorAttributeName: UIColor.whiteColor(), 
      NSFontAttributeName: navBarFont 
     ] 
     self.navigationController?.navigationBar.titleTextAttributes = navBarAttributesDictionary 
} 

搜索欄屬性:

searchController.searchResultsUpdater = self 
searchController.dimsBackgroundDuringPresentation = false 
definesPresentationContext = true 
searchController.searchBar.placeholder = "Search for new friends" 
tableView.tableHeaderView = searchController.searchBar 
searchController.searchBar.backgroundColor = ColorHelper.sharedInstance.LightPink() 
searchController.searchBar.barTintColor = ColorHelper.sharedInstance.LightPink() 
searchController.searchBar.backgroundImage = UIImage() 

The result

這似乎爲我ColorHelper返回不同的值LightPink但doesn't。我檢查了HEX值的顏色,它是不正確地顯示顏色的導航欄,比實際情況要輕一點。任何想法爲什麼?改變.barStyle沒有改變任何東西。

+0

我已經更新了我的回答如下,有兩個你的問題的答案s –

回答

1

相同顏色:

我有同樣的問題,我的(我的UINavigationBar搭配同色系的1x1像素的圖像)設置backroundImageUISearchBar解決它。並注意transluent場 - 它必須具有相同的值作爲UINavigationBar

分隔符:

要刪除導航欄和搜索欄之間的分隔符,你可以在你的AppDelegate

UINavigationBar.appearance().setBackgroundImage(UIImage(), forBarMetrics: .Default) 
UINavigationBar.appearance().shadowImage = UIImage() 
使用此代碼

但它只能如果你設置transluent場假

+0

'self.navigationController .navigationBar.setBackgroundImage(UIImage的(),forBarMetrics:.DEFAULT)? self.navigationController .navigationBar.shadowImage = UIImage的()'解決了這個問題對我來說 – Percolator

1

我想你的NavBar中有一個半透明的。您應該使用此代碼關閉Transculent,您可以在viewDidLoad方法中使用它。

self.navigationController?.navigationBar.translucent = false 

此外,您可以在界面生成器中切換半透明。選擇您的導航控制器,然後在文檔大綱中選擇導航欄,並在屬性檢查器取消選中半透明選項。

如果你不想你的消失時的導航欄用戶輕按您的搜索欄使用本;

searchController.dimsBackgroundDuringPresentation = false 
searchController.hidesNavigationBarDuringPresentation = false 
+0

在我原來的文章中,靈魂似乎在圖片中看到的視圖起作用,它們現在是相同的顏色。問題是,當我選擇搜索欄時,用於搜索的導航欄不可見。任何建議如何解決? – Percolator

+0

@Percolator你解決了這個問題嗎? ? – emresancaktar