// 实现原理及思路:不同种类的皮肤放在不同的文件夹下,用一个plist文件存放不同控制器下的控件的背景颜色
//plist文件名称为控制器的名称,内部的数据字典的key value对自定义一个命名规则,容易读取即可
//
#import "MYScreenToll.h"
@interface MYScreenToll ()
@end
//皮肤设置
static NSString*_skin;
@implementation MYScreenToll
//类初始化加载的时候调用
+(void)initialize
{
_skin=[[NSUserDefaults standardUserDefaults]objectForKey:@"skin1"];
if (_skin==nil) {
_skin=@"blue";
}
}
//类方法
+(void)saveSkin:(NSString*)skin
{
_skin=skin;
//保存
NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
[user setObject:skin forKey:@"skin1"];
[user synchronize];
}
+(UIImage*)loadImage:(NSString*)imageName
{
NSString*pathName=[NSString stringWithFormat:@"skin/%@/%@",_skin,imageName];
UIImage *image=[UIImage imageNamed:pathName];
return image;
}
+(UIColor*)loadColor:(NSString*)key
{
//拼接路径
NSString *plistName=[NSString stringWithFormat:@"skin/%@/color.plist",_skin];
//读取plist文件
NSString*str=[[NSBundle mainBundle]pathForResource:plistName ofType:nil];
NSData *data=[NSData dataWithContentsOfFile:str];
NSDictionary *dict=[NSJSONSerialization JSONObjectWithData:data options:0 error:NULL];
NSString*colorStr=[dict objectForKey:key];
NSArray *rgb=[colorStr componentsSeparatedByString:@","];
UIColor *col=[[UIColor alloc]initWithRed:[rgb[0] intValue]/255.0 green:[rgb[1] intValue]/255.0 blue:[rgb[2] intValue]/255.0 alpha:1];
return col;
}
@end