簡體   English   中英

PushViewController並設置導航欄的顏色和標題

[英]PushViewController & set navigation bar color and title

我在按鈕中做了一個推功能:

@IBAction func prodButton(sender: AnyObject) {

    let storyboard = UIStoryboard(name: "Main", bundle: nil)

    var secondViewController = CollectionViewController()

    secondViewController = storyboard.instantiateViewControllerWithIdentifier("CollectionViewController") as! CollectionViewController

    self.navigationController?.pushViewController(secondViewController, animated: true)
}

該按鈕推到secondViewController上,但是當我查看第二個視圖控制器的導航欄時,我注意到它已自動設置了一個后退按鈕。 問題在於此后退按鈕的顏色為淺藍色,不適合我的設計。 我試圖在viewDidAppear中進行更改

self.navigationItem.leftBarButtonItem?.tintColor = UIColor.redColor()

以及條形顏色:

self.navigationController?.navigationBar.barTintColor = UIColor(red: 65, green: 61, blue: 116, alpha: 1.0)

但沒有任何變化。

如果有人幫助我,我將非常感激。

提前致謝。

嘗試一次設置您的顏色,此后所有地方都將使用相同的顏色:

let navBar = UINavigationBar.appearance()
navBar.tintColor = UIColor.redColor()

您應該將此代碼放在AppDelegate中。 如果使用,也可以在情節提要中設置barTint。

采用

   //Func Alter color navigation bar
   func AlteraCorNavigationBar(Navigation:UINavigationController){
       Navigation.navigationBar.tintColor = CorTextoNavigationBar()
       //Navigation.navigationBar.barTintColor = CorPredominante()
       Navigation.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : CorTextoNavigationBar(), NSFontAttributeName : UIFont(name: "ArialHebrew-Light", size: 22)!]
   }


   //func CorPredominante()->UIColor{
       //return UIColor.redColor()
       //(rgba: "#ecf0f1")
       // YOU CAN LIBRARY COLOR RGBA [HERE][1] AND USE UIColor(rgba: "#b6011a")
   //}


   func CorTextoNavigationBar()->UIColor{
       return UIColor(red: 65, green: 61, blue: 116, alpha: 1.0) 
   }

用於在視圖控制器中調用:

class NewViewController: UIViewController {

      override func viewDidLoad() {
          super.viewDidLoad()

          AlteraCorNavigationBar(navigationController)
      }

}

我發現了錯誤。 顏色應由255划分:

UINavigationBar.appearance().tintColor = UIColor(red: 149.0 / 255.0, green: 148.0 / 255.0, blue: 192.0 / 255.0, alpha: 0.5)

UINavigationBar.appearance().barTintColor = UIColor(red: 65.0 / 255.0, green: 61.0 / 255.0, blue: 116.0 / 255.0, alpha: 1.0)

謝謝大家的幫助;)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM