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 中。如果你使用它,你也可以在 Storyboard 中设置 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)

谢谢大家的帮助;)