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
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)
You should use this:
navigationController?.navigationBar.barTintColor = .purple
navigationController?.navigationBar.tintColor = .white
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
}
Swift
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.tintColor = UIColor.white
}
in swift 2.0 use
self.navigationController!.navigationBar.tintColor = UIColor.whiteColor();
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
}
}