pod 'VOThemeManager'
VOThemeManager
文件夹内所有源码拖入项目YYCache
主题数据使用 YYCache 存储,不同主题所存放的文件夹不同。主题值的
themeAppliers 应用主题数据的方法,themeObjs 当前要应用主题的对象,它们都是 NSMapTable 对象,在被释放后会自动从 NSMapTable 中删除 themeAppliers 的 key 是 主键,value 为 block 对象。
themeObjs 的 key 是 主键,value 为某个对象,通常为某种视图对象
1.新增/修改主题
[VOThemeManager setData:processedDic forTheme:@"test"];
注:新增主题之后不会自动使用新增的主题。
2.加载完主题数据后,应用指定的主题。例如:
VOThemeManager.currentTheme = @"test"; /* 设置为test主题 */
VOThemeManager.currentTheme = nil; /* 不使用主题 */
3.添加要使用的主题对象。例如:
[VOThemeManager setThemeObject:self.testButton /* 主题对象 */
forKey:@"btn1_bgColor" /* 主键,用于关联主题值,主题对象,应用方式,默认值 */
defaultBlock:^id(UIButton *button) { /* 获取默认值,不使用主题时将重设为此值 */
return button.backgroundColor;
}
applier:^(UIButton *button, UIColor *color) { /* 应用主题的方式 */
button.backgroundColor = color;
}];