Change the color of iOS Navigation Bar

前端 未结 9 2122
挽巷
挽巷 2020-12-07 13:57

I\'m trying to change the color of my navigator bar but I found that it\'s only impossible if the navigator is the root one.

I\'m trying this:

self.n         


        
9条回答
  •  难免孤独
    2020-12-07 14:22

    In fact, i found that the solution was to use in the 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
    }
    

    and then in each view controller, that we need another background color or something else

    1. the segue should be different than "show"

    2. use the func 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()]
      }
      

提交回复
热议问题