主题切换LNTheme简介

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的阅读 14,605评论 5 6
  • Correctness AdapterViewChildren Summary: AdapterViews can...
    MarcusMa阅读 12,886评论 0 6
  • 静静的夜 没有一点颜色 黑暗笼罩在心头 风雪蔓延 狂沙弥漫 躲在被子里瑟瑟发抖 暖气开到了最大 也不觉得暖 心还是...
    青清风阅读 3,012评论 0 17
  • 1,百度百科链接 百度百科:电动调节阀 2,问题一 通过接收工业自动化控制系统的信号(如:4~20mA)来驱动阀门...
    microcosmv阅读 2,383评论 0 0
  • 今天是2017年9月13日星期四。今天群里家人做的早餐既营养均衡,又颜色多样。 群里丹丹老师分享素食也会带来营养过...
    小蔡xc阅读 2,144评论 0 0

友情链接更多精彩内容