GithubHelp home page GithubHelp logo

mainstayz / dknightversion Goto Github PK

View Code? Open in Web Editor NEW

This project forked from draveness/dknightversion

0.0 2.0 0.0 4.74 MB

DKNightVersion is a lightweight iOS framework adding night mode to your iOS app.

License: MIT License

Objective-C 77.04% Ruby 14.31% HTML 8.64%

dknightversion's Introduction

DKNightVersion Version Build Status MIT License Platform

DKNightVersion is a light weight framework. It's mainly built through objc/runtime library and reflection, providing a neat approach adding night mode to your iOS app. A great many codes of this framework is automatically generated by Ruby script.

The most delightful feature of DKNightVersion is that it appends one more property nightColor to frequently-used UIKit components and provides you a default night mode theme. It is easily-used and well-designed. Hope you have a great joy to use DKNightVersion to integrate night mode in your Apps.

Demo

Installation with CocoaPods

CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like DKNightVersion in your projects. See the Get Started section for more details.

Podfile

pod "DKNightVersion", "~> 0.7.0"

Usage

Just add one line of code in your precompiled header, or import it where you need.

#import "DKNightVersion.h"

How to use

Using night color

DKNightVersion is based on property nightColor, such as nightBackgroundColor nightTextColor and etc.

Assign the night mode color you want to the UIKit component like this:

self.view.nightBackgroundColor = [UIColor blackColor];
self.label.nightTextColor = [UIColor whiteColor];

Using DKNightVersionManager change theme

Use DKNightVersionManager sets the theme.

[DKNightVersionManager nightFalling];

If you'd like to switch back to normal mode:

[DKNightVersionManager dawnComing];

It's pretty easy to swich theme between night and normal mode.

Make your own customize

Notification

nightFalling method will post DKNightVersionNightFallingNotification when it is called. Similarly, dawnComing will post DKNightVersionDawnComingNotification. You can observe these notification in proper place, and make your own customize easily.

RespondClasses

If you want your own class changing color while switch theme.

You are supposed to add it to respondClasseses set. In the new version, in order to prevent subclass inheritance superclass's night color, I add respondClasseses set.

Use addClassToSet: or removeClassToSet: method to deal with it.

[DKNightVersionManager addClassToSet:self.class];
[DKNightVersionManager removeClassToSet:self.class];

If you don't add your own classes to this set, DKNightVersionManager will prevent it from changing color when switch theme.

Use respondClasseses to get all respond classes which will change color when nightFalling or dawnComing.

NSSet *set = [DKNightVersionManager respondClasseses];

JSON

There is a json file in Generator folder named property.json, you can change the color in it, which will cuz the default color changing to the color you want.

{
    "UIView":
    {
        "backgroundColor": "0x343434",
        "tintColor": "0xffffff"
    },
    "UILabel":
    {
        "textColor": "0x5d5d5d"
    },
    "UINavigationBar":
    {
        "barTintColor": "0x444444"
    },
    "UIButton":
    {
        "titleColor": "0x5F80AC"
    },
    "UIScrollView":
    {
        "backgroundColor": "0x343434"
    },
    "UITableView":
    {
        "backgroundColor": "0x343434",
        "separatorColor": "0x313131"
    },
    "UITableViewCell":
    {
        "backgroundColor": "0x343434"
    }
}

And run rake in terminal under folder Pods/DKNightVersion.

This ruby script is based on the Cocoapods components Xcodeproj. If there is a NoMethodError, you should install it first or run bundle install in DKNightVersion folder.

This command will automatically do everything for you.

Using default night version

If you set useDefaultNightColor property for singleton manager to YES, which is the default value. DKNightVersion will provide you a default night mode.

And you can also customize the color through assign color value to nightColor property. And we will first pick color you specified instead of default behavior.

Optionally, turn off the default night mode and set it on your own is also supported.

[DKNightVersionManager setUseDefaultNightColor:NO];

Picking Color

DKNightVersionManager will pick the proper color following these two rules.

  1. useDefaultNightColor == YES (The default behavior)

     nightColor > defaultNightColor > normalColor
    
  2. useDefaultNightColor == NO

     nightColor > normalColor
    

Contribute

Feel free to open an issue or pull request, if you need help or there is a bug.

Contact

License

DKNightVersion is available under the MIT license. See the LICENSE file for more info.

Todo

  • Documentation

dknightversion's People

Contributors

bromine0x23 avatar draveness avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.