Change color of Back button in navigation bar

后端 未结 26 1919
孤街浪徒
孤街浪徒 2020-12-02 05:58

I am trying to change the color of the Settings button to white, but can\'t get it to change.

I\'ve tried both of these:

navigationItem.leftBarButton         


        
相关标签:
26条回答
  • 2020-12-02 06:07

    Swift 4.2

    Change complete app theme

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
            // Override point for customization after application launch.
    
            UINavigationBar.appearance().tintColor = .white
    
            return true
        }
    

    Change specific controller

    let navController = UINavigationController.init(rootViewController: yourViewController) 
    navController.navigationBar.tintColor = .red
    
    present(navController, animated: true, completion: nil)
    
    0 讨论(0)
  • 2020-12-02 06:08

    You should use this:

    navigationController?.navigationBar.barTintColor = .purple
    navigationController?.navigationBar.tintColor = .white
    
    0 讨论(0)
  • 2020-12-02 06:09

    Lets try this code:

     func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
    
        let navigationBarAppearace = UINavigationBar.appearance()
        navigationBarAppearace.tintColor = UIColor.whiteColor()  // Back buttons and such
        navigationBarAppearace.barTintColor = UIColor.purpleColor()  // Bar's background color
        navigationBarAppearace.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()]  // Title's text color
    
        self.window?.backgroundColor = UIColor.whiteColor()
        return true
    }
    
    0 讨论(0)
  • 2020-12-02 06:11

    Swift

     override func viewDidLoad() {
         super.viewDidLoad()
    
     self.navigationController?.navigationBar.tintColor = UIColor.white
     }
    
    0 讨论(0)
  • 2020-12-02 06:13

    in swift 2.0 use

    self.navigationController!.navigationBar.tintColor = UIColor.whiteColor();
    
    0 讨论(0)
  • 2020-12-02 06:13

    If you already have the back button in your "Settings" view controller and you want to change the back button color on the "Payment Information" view controller to something else, you can do it inside "Settings" view controller's prepare for segue like this:

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
        if segue.identifier == "YourPaymentInformationSegue"
        {
            //Make the back button for "Payment Information" gray:
            self.navigationItem.backBarButtonItem?.tintColor = UIColor.gray               
        }
    }
    
    0 讨论(0)
提交回复
热议问题