Dknightversion:https://github.com/draveness/dknightversion
The rationale is to use a singleton object to store the color, and then Pass the Objc_setassociatedobject and objc_ in the runtime Getassociatedobject to complete the transfer of the color to be saved between two objects (purely personal view)
Here is the GIF:
Here is the Code section:
Import Uikitclass Viewcontroller:uiviewcontroller {@IBOutlet weak var changebutton:uibutton! @IBOutlet weak var testswitch:uiswitch! Override Func Viewdidload () {super.viewdidload () Self.title = "Night Mode"//navigation bar background self.na Vigationcontroller?. Navigationbar.dk_bartintcolorpicker = Dkcolorwithrgb (0XFFFFFF, 0x343434)//The item on the navigation bar and return color Self.navigationc Ontroller?. Navigationbar.dk_tintcolorpicker = Dkcolorwithcolors (Uicolor.redcolor (), Uicolor.whitecolor ())//view background color Self.view.dk_backgroundColorPicker = Dkcolorwithrgb (0XFFFFFF, 0x343434)//button title color Self.changeButton.dk_se Ttitlecolorpicker (Dkcolorwithcolors (Uicolor.redcolor (), Uicolor.whitecolor ()), forstate:. Normal)//Switch Color Self.testSwitch.dk_onTintColorPicker = dkcolorwithcolors (Uicolor.greencolor (), Uicolor.redco Lor ())} @IBAction func Change (sender:anyobject) {//Determines whether the current is a night mode if DknightversionmanAger.currentthemeversion () = = dkthemeversion.night {//Switch to Daylight mode dknightversionmanager.dawncoming () } else {//switch to Night Mode dknightversionmanager.nightfalling ()}}}
In your project, you can set two colors for the following controls, daylight mode and night mode, respectively
When the settings are complete, you can switch to daylight mode by calling the following code
Switch to Daylight mode dknightversionmanager.dawncoming ()
or call code to switch to night mode.
Switch to Night mode dknightversionmanager.nightfalling ()
It's pretty simple to use (but it needs to be set for every control, and it's very painful for larger projects) ...
Basic use of dknightversion (Night mode)