mohuifen / DKNightVersion

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DKNightVersion

language 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. 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.8.1"

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 must 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 add more color property, which will add night color to the corresponding property you want.

{
    "UIView": 
    [
        "backgroundColor"
    ],
    "UILabel":
    [ 
        "textColor"
    ],
    "UINavigationBar":
    [ 
        "barTintColor",
        "tintColor"
    ],
    "UITabBar":
    [ 
        "barTintColor"
    ],
    "UIButton":
    [ 
        "titleColor"
    ],
    "UIBarButtonItem":
    [ 
        "tintColor"
    ],
    "UITableView":
    [ 
        "separatorColor"
    ]
}

And run rake in terminal under folder Pods/DKNightVersion if you are using Cocoapods.

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.

Picking Color

DKNightVersionManager will pick the proper color following this rule.

nightColor > normalColor

But I suggest to assign every UIKit component a night color to prevent errors.

Contribute

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

More

  • ImageView support

Contact

Todo

  • Documentation

License

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

The MIT License (MIT)

Copyright (c) 2015 Draveness

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

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

License:MIT License


Languages

Language:Objective-C 77.3%Language:Ruby 15.0%Language:HTML 7.6%