Coder Social home page Coder Social logo

ryanfu / lntheme Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vvusu/lntheme

0.0 1.0 0.0 16.8 MB

动态主题切换框架,支持本地多主题配置或者网络多主题配置

License: MIT License

Ruby 0.79% Objective-C 73.05% C++ 2.58% C 22.66% Shell 0.14% Makefile 0.78%

lntheme's Introduction

Demo - Installation - Documents - Contribution - 中文文档

LNTheme

Dynamic theme switching framework that supports local multi-theme configuration or network multi-theme configuration.

Demo

Use Netease cloud music API

Installation

CocoaPods

Installation with CocoaPods:

pod 'LNTheme'

Carthage

Installation with Cartfile:

github "wedxz/LNTheme"

Source installation

Copy all the files in the "LNTheme / LNTheme" folder into your project

Documents

Basic use method

The theme switch uses the Name to identify, a theme can correspond to multiple json configuration files. The framework is mainly used for theme configuration with json files. You need to add the json configuration file locally, or manually register the json file.

Manually register the json file using the following method:

+ (void)addTheme:(NSString *)themeName forPath:(NSString *)path;

Json file format is as follows:

{
    "colors": {
        "c1": "b2770f",
        "c2": "b2770f",
        "c3": "aaaaaa",
        "c4": "b2770f",
        "c5": "b2770f",
   },
    "fonts": {
        "f1": "8",
        "f2": "9",
        "f3": "10",
        "f4": "14",
        "f5": "16",
    },
    "coordinators": {
        "Offset1": "{0,10}",
        "Offset2": "{0,30}",
        "Offset3": "{-15,10}",
        "Offset4": "{-20,50}"
    }
}

Json file colors, fonts, coordinators for the fixed wording, you can add other Key. The corresponding identity can be the same, but the same key will be overwritten. It is recommended to maintain with a set of standards.

Colors format:

RGB / ARGB / RRGGBB / AARRGGBB

Fonts format:

"16"

Coordinators format:

{1,2} / {1,2,3,4} / {1,2,3,4,5,6}

How to use LNTheme

NSObject+LNTheme.hThis class contains the set-up methods that are supported.

@property (strong, nonatomic)NSMutableDictionary *themePickers;
- (void)updateFont;
- (void)updateTheme;
- (void)ln_customFontAction:(id(^)(void))block;
- (void)ln_customThemeAction:(id(^)(void))block;
- (void)setThemePicker:(NSObject *)object selector:(NSString *)sel picker:(LNThemePicker *)picker;
@end

@interface UIColor (LNTheme)
+ (UIColor *)colorWithHexString:(NSString *)hexString;
@end
...

Color multi-theme settings

//UIView 
[self.view ln_backgroundColor:@"c8"];

//UILabel 
[self.label ln_textColor:@"c5"];

//UITextField 
[self.textField ln_textColor:@"c8"];

//UISwitch 
[self.testSwitch ln_onTintColor:@"c8"];

Font multi-theme settings

//UINavigationBar & titleTextAttributes
[navBar ln_titleTextAttributesColorType:@"c9" font:@"f10"];

Picture multi-theme settings

//UIImageView
[self.imageview ln_imageNamed:@"cm2_chat_bg"];

//UIButton
[self.button ln_backgroundImageNamed:@"cm2_edit_cmt_bg" forState:UIControlStateHighlighted];

Picture custom colors can be used by the method provided by this extension of UIImage + Tint.h.

Topic related attributes

Get the relevant dependency values using the methods contained in LNTheme.h, and get them through Key.

+ (UIFont *)fontForType:(NSString *)type;
+ (UIImage *)imageNamed:(NSString *)name;
+ (UIColor *)colorForType:(NSString *)type;
+ (id)otherForType:(NSString *)type;
+ (CGSize)sizeForType:(NSString *)type;
+ (CGRect)rectForType:(NSString *)type;
+ (CGPoint)pointForType:(NSString *)type;
+ (CGVector)vectorForType:(NSString *)type;
+ (UIEdgeInsets)edgeInsetsForType:(NSString *)type;
+ (CGAffineTransform)affineTransformForType:(NSString *)type;

Other

If you do not include the set options, you can manually refresh the control-related properties, using the methods contained in NSObject + LNTheme.h:

- (void)ln_customThemeAction:(id(^)(void))block;

For example, when the topic is switched, the UITableView is refreshed

__weak typeof(self) wself= self;
[self ln_customThemeAction:^id {
    [wself.tableView reloadData];
    return nil;
}];

Contribution

vvusu

License

Copyright (c) 2016 vvusu

lntheme's People

Contributors

vvusu avatar

Watchers

fuqiang 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.