LNTheme 1.0.1

LNTheme 1.0.1

vvusu 维护。



LNTheme 1.0.1

  • wedxz

示例 - 安装 - 文档 - 贡献 - 中文文档

LNTheme

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

示例

使用网易云音乐 API

安装

CocoaPods

使用 CocoaPods 进行安装

pod 'LNTheme'

Carthage

使用 Cartfile 进行安装

github "wedxz/LNTheme"

源码安装

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

文档

基本使用方法

主题切换使用名称来识别,一个主题可以对应多个json配置文件。该框架主要用于使用json文件进行主题配置。您需要本地添加json配置文件,或手动注册json文件。

使用以下方法手动注册json文件

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

json文件格式如下

{
    "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文件中的colorsfontscoordinators用于固定文字,您可以添加其他键。对应的标识可以相同,但相同的键将被覆盖。建议与一套标准保持一致。

颜色格式

RGB / ARGB / RRGGBB / AARRGGBB

字体格式

"16"

坐标格式

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

如何使用LNTheme

NSObject+LNTheme.h这个类包含支持的设置方法。

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

颜色多主题设置

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

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

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

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

字体多主题设置

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

图片多主题设置

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

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

图片自定义颜色可以通过该扩展为UIImage + Tint.h提供的方法使用。

主题相关属性

使用LNTheme.h中包含的方法获取相关依赖值,并通过键获取它们。

+ (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;

其他

如果不包含设置选项,您可以使用包含在NSObject + LNTheme.h中的方法手动刷新与控件相关的属性。

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

例如,当主题切换时,UITableView将被刷新

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

贡献

vvusu

版权

版权所有 (c) 2016 vvusu