美文网首页
主题切换LNTheme简介

主题切换LNTheme简介

作者: vvusu_w | 来源:发表于2017-08-01 11:12 被阅读55次

GitHub地址:https://github.com/wedxz/LNTheme

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

相关文章

  • 主题切换LNTheme简介

    GitHub地址:https://github.com/wedxz/LNTheme LNTheme Dynamic...

  • 切换主题

    日/夜间主题 使用Android Support Library 中的 UiMode来做“日/夜间主题” 以背景颜...

  • 主题切换

    主题切换在前几年很火的一个技术,俗称换肤!今天我们来实现下这个主题是怎么切换的。主体思路:1.要求的图片名是一样的...

  • 主题切换

    1.什么是主题切换? 就是在一个app中实现不同的主题.在同一种主题下,所有字体颜色一样,背景图的样式一样. 2....

  • 主题切换

    http://www.open-open.com/lib/view/open1460934455593.html ...

  • Android 实现切换主题皮肤功能

    简介 正文 首先我们先来做个简单的一键切换主题的功能。查看代码如下: 但是这种情况下呢,一键切换皮肤,app需要退...

  • 来自B站的开源的MagicaSakura源码解析

    简介 MagicaSakura是Bilibili开源的一套主题切换框架,其功能是在不重启Activity的情况下,...

  • Flutter 学习 之 主题设置 ThemeData

    基于ThemeData 实现主题切换 1. 实现可以亮暗主题切换2. 实现可以颜色主题的切换3.当主题为白色的时候...

  • iOS 答题功能实现

    最近项目中答题模块进行了优化,可切换主题,切换字体大小,答题背题模式。 答题主界面,可切换答题,背题模式 切换主题...

  • Android切换主题

    values-v21/styles.xml 切换主题: 效果图: 源码地址:https://github.com/...

网友评论

      本文标题:主题切换LNTheme简介

      本文链接:https://www.haomeiwen.com/subject/afcjlxtx.html