I am trying to make it so that the user, when turning dark mode on(using the switch), would change the table view cells background color to black(hence being a dark mode). I was also wondering on how to change the color of the navigationbar when the switch is on as well.
Below is what I have tried(full code):
import Foundation
import UIKit
class SideMenuController8: UITableViewController{
@IBOutlet var TableViewColor: UITableView!
@IBOutlet weak var OpenSettings: UIBarButtonItem!
@IBOutlet weak var mSwitch: UISwitch!
@IBOutlet weak var dSwitch: UISwitch!
override func viewDidLoad() {
self.navigationController?.navigationBar.topItem!.title = "Settings"
if revealViewController() != nil {
OpenSettings.target = revealViewController()
OpenSettings.action = #selector(SWRevealViewController.revealToggle(_:))
view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
// mSwitch.layer.borderWidth = 1
// mSwitch.layer.borderColor = UIColor.white.cgColor
let onColor = UIColor(red: CGFloat(0.0), green: CGFloat(122.0 / 255.0), blue: CGFloat(1.0), alpha: CGFloat(1.0))
let offColor = UIColor.white
//Notifications On Switch
mSwitch.isOn = false
/*For on state*/
mSwitch.onTintColor = onColor
/*For off state*/
mSwitch.tintColor = offColor
mSwitch.layer.cornerRadius = 16
mSwitch.backgroundColor = offColor
//Dark Mode Switch
dSwitch.isOn = false
/*For on state*/
dSwitch.onTintColor = onColor
/*For off state*/
dSwitch.tintColor = offColor
dSwitch.layer.cornerRadius = 16
dSwitch.backgroundColor = offColor
if (dSwitch.isOn == true){
TableViewColor.reloadData()
print("Dark Mode Switch is on")
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Here is another pic showing my main storyboard