Change color of Back button in navigation bar

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

    I prefer custom NavigationController rather than setting global ui, or put in ViewController.

    Here is my solution

    
    class AppNavigationController : UINavigationController {
    
      override func viewDidLoad() {
        super.viewDidLoad()
        self.delegate = self
      }
    
      override func viewWillAppear(_ animated: Bool) {
    
      }
    
    }
    extension AppNavigationController : UINavigationControllerDelegate {
    
      func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
        let backButtonItem = UIBarButtonItem(
          title: "   ",
          style: UIBarButtonItem.Style.plain,
          target: nil,
          action: nil)
        backButtonItem.tintColor = UIColor.gray
        viewController.navigationItem.backBarButtonItem = backButtonItem
      }
    
      func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
    
      }
    
    }
    
    

    Also you don't need to mess with Apple Api like EKEventEditViewController,PickerViewController and so on if you use global settings ui like UIBarButtonItem.appearance().tintColor = .white

提交回复
热议问题