I have in my project (Swift) a TableViewController and also a ViewController. I have a switch that changes the color of my app (to dark). The problem is that it only changes it in the scene that I am in. If I go to another scene, it's white.
My code:
import UIKit
class BaseTableViewController: UITableViewController {
@IBOutlet var InicioTable: UITableView!
@IBOutlet weak var cell2: UITableViewCell!
@IBOutlet var viewTable: UITableView!
@IBOutlet weak var celldarkmode: UITableViewCell!
@IBOutlet weak var label: UILabel!
@IBOutlet weak var switchController: UISwitch!
@IBAction func changeSwitch(_ sender: UISwitch) {
if switchController.isOn == true
{
self.navigationController?.navigationBar.isTranslucent = false
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]//user global variable
self.navigationController?.navigationBar.barStyle = UIBarStyle.black //user global variable
self.navigationController?.navigationBar.tintColor = UIColor.black //user global variable
UIApplication.shared.statusBarStyle = .lightContent
label.textColor = UIColor.white
self.cell2.backgroundColor = UIColor.black
self.tabBarController?.tabBar.barTintColor = UIColor.black
view.backgroundColor = UIColor.init(red: 0.1, green: 0.1, blue: 0.1, alpha: 1.0)
}
else
{
self.navigationController?.navigationBar.isTranslucent = false
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.black]//user global variable
self.navigationController?.navigationBar.barStyle = UIBarStyle.default //user global variable
self.navigationController?.navigationBar.tintColor = UIColor.white //user global variable
UIApplication.shared.statusBarStyle = .default
label.textColor = UIColor.black
self.cell2.backgroundColor = UIColor.white
self.tabBarController?.tabBar.barTintColor = UIColor.white
view.backgroundColor = UIColor.groupTableViewBackground
}
}
}