繁体   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