更改iOS导航栏的颜色

安东尼·沙欣(Anthony Shahine):

我正在尝试更改导航器栏的颜色,但是我发现只有导航器是根导航器,这才是不可能的。

我正在尝试:

self.navigationController?.navigationBar.translucent = true

self.navigationController!.navigationBar.barTintColor = UIColor.blueColor()

我所有Viewcontrollers与导航器控制器有关。但是什么都没有改变。实际上,我试图从情节提要中进行相同的操作,但只有在我处于第一个导航器中时,它才有效。

我试图阅读与此问题相关的所有内容,但未发现任何内容

我可以像这样将任何项目添加到导航栏

let HomeImage = UIImage(named: "home")!
    let Home : UIBarButtonItem = UIBarButtonItem(image: HomeImage,  style: .Plain, target: self, action: "home:")
    navigationItem.rightBarButtonItem = Home
安东尼·沙欣(Anthony Shahine):

实际上,我发现该解决方案将用于AppDelegate.siwft

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    UINavigationBar.appearance().barTintColor = UIColor(red: 0, green: 0/255, blue: 205/255, alpha: 1)
    UINavigationBar.appearance().tintColor = UIColor.whiteColor()
    UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()]

    return true
}

然后在每个视图控制器中,我们需要另一种背景色或其他颜色

  1. segue应该不同于“ show”

  2. 使用功能 viewWillAppear

     override func viewWillAppear(animated: Bool) {
         super.viewWillAppear(animated)
         self.navigationController?.navigationBar.barTintColor = UIColor.whiteColor()
         self.navigationController?.navigationBar.tintColor = UIColor.blueColor()
         self.navigationController!.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.blueColor()]
    }
    

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章