Basic use of dknightversion (Night mode)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.