Change color of Back button in navigation bar

后端 未结 26 1917
孤街浪徒
孤街浪徒 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:01

    This code changes the arrow color

    self.navigationController.navigationBar.tintColor = UIColor.whiteColor();
    

    If this does not work, use the code below:

    self.navigationBar.barStyle = UIBarStyle.Black
    self.navigationBar.tintColor = UIColor.whiteColor()
    

    Swift 3 Notes

    UIColor.whiteColor() and similar have been simplified to UIColor.white

    Also, many previously implicit optionals have been changed to explicit, so you might need:

    self.navigationController?.navigationBar =
    
    0 讨论(0)
  • 2020-12-02 06:02

    You have one choice hide your back button and make it with your self. Then set its color.

    I did that:

    self.navigationItem.setHidesBackButton(true, animated: true)
    let backbtn = UIBarButtonItem(title: "Back", style:UIBarButtonItemStyle.Plain, target: self, action: "backTapped:")
    self.navigationItem.leftBarButtonItem = backbtn
    self.navigationItem.leftBarButtonItem?.tintColor = UIColor.grayColor()
    
    0 讨论(0)
  • 2020-12-02 06:03

    It will be solved with this line in -(void)viewDidLoad:

    self.navigationItem.backBarButtonItem.tintColor = UIColor.whiteColor;
    
    0 讨论(0)
  • 2020-12-02 06:05

    Swift 3

    The most upvoted answer is not correct for Swift 3.

    The correct code to change color is:

    self.navigationController?.navigationBar.tintColor = UIColor.white
    

    If you want to change color, change UIColor.white above to the desired color

    0 讨论(0)
  • 2020-12-02 06:05

    Add following code to didFinishLaunchingWithOptions function in AppDelegate.swift

    var navigationBarAppearace = UINavigationBar.appearance()
    
    navigationBarAppearace.tintColor = uicolorFromHex(0xffffff) // White color
    navigationBarAppearace.barTintColor = uicolorFromHex(0x034517) // Green shade
    
    // change navigation item title color
    navigationBarAppearace.titleTextAttributes =[NSForegroundColorAttributeName:UIColor.whiteColor()]
    
    0 讨论(0)
  • 2020-12-02 06:07

    You can change the global tint color in your storyboard by clicking on an empty space on the board and select in the right toolbar "Show the file inspector", and you will see in the bottom of the toolbar the "Global Tint" option.

    0 讨论(0)
提交回复
热议问题