MCStyle
为 iOS UI 配置自定义和智能样式
一款 App 的颜色、字体、图片等资源是有限的,此项目的宗旨是统一样式管理,方便换肤。 如果你的项目是一款 UI 类的开源库,而你又希望打包成 pod 库,又希望用户能自定义一些样式,那 MCStyle 就是为你定制的。 如果你的项目的样式管理混乱,可以直接使用 MCStyle, enjoy time!
安装
pod 'MCStyle'
结构
MCFont 通用字体
MCColor 通用颜色
MCStyle 通用样式
MCFontConfg 自定义字体
MCColorConfig 自定义颜色
MCStyleConfig 自定义样式
MCStyleManager 样式管理器
自定义
MCFont +custom: 通用字体
MCColor +custom: 通用颜色
MCStyle +customImage: 通用样式
MCFontConfg -custom: 自定义字体
MCColorConfig -custom: 自定义颜色
MCStyleConfig -custom: 自定义样式
通过自定义字体、颜色、样式接口传入MCStyleManager,从而实现样式的自定义。
接入
1. load配置
json文件格式参考 Custom*.json
[MCStyleManager share].colorStyleDataCallback = ^NSDictionary *(void) {
NSString *path = [[NSBundle mainBundle] pathForResource:@"CustomColor" ofType:@"json"];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:path] options:NSJSONReadingMutableContainers error:nil];
return dict[@"data"];
};
[MCStyleManager share].fontStyleDataCallBack = ^NSDictionary *(void) {
NSString *path = [[NSBundle mainBundle] pathForResource:@"CustomFont" ofType:@"json"];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:path] options:NSJSONReadingMutableContainers error:nil];
return dict[@"data"];
};
[MCStyleManager share].styleDataCallback = ^NSDictionary *(void) {
NSString *path = [[NSBundle mainBundle] pathForResource:@"CustomStyle" ofType:@"json"];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:path] options:NSJSONReadingMutableContainers error:nil];
return dict[@"data"];
};
[[MCStyleManager share] loadData];
2. 使用
颜色
[MCColor colorI] or [MCColor custom:@"custom"]
字体大小
[MCFont fontI] or [MCFont custom:@"font"]
图片
[MCStyle imageI] or [MCStyle customImage:@"iamge"]
边距
[MCStyle contentInsetI] or II III
许可协议
MCStyle 适用于 MIT 许可协议。