码迷,mamicode.com
首页 > 其他好文 > 详细

UI中对于选择主题的处理方法

时间:2015-09-17 15:34:15      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:主题

- (instancetype)init

{

    self = [super init];

    if (self) {//初始化_themeName

        

        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

        NSString *key = [defaults objectForKey:KThemeDefaultKey];

        if (key.length == 0) {

            

            _themeName = @"New PinkPink";

           

        } else{

             _themeName = key;

        }

        //获取文件路径

         NSString *filePath = [[NSBundle mainBundle]pathForResource:@"theme" ofType:@"plist"];

        //初始化_themeConfiger

        _themeConfiger = [NSDictionary dictionaryWithContentsOfFile:filePath];

        

        //取得状态栏状态

        [self initTabBarStyle];

    }

    return self;

}


//创建单例

+ (ThemeManager *)shareThemeManage{

    

    static dispatch_once_t onceToken;

    dispatch_once(&onceToken, ^{

        themeManage = [[ThemeManager alloc]init];

    });

    return themeManage;

}



//根据imageName返回图片

- (UIImage *)themeImageWithImageName:(NSString *)imageName{

    

    //获取文件路径

    NSString *themePath = [[[NSBundle mainBundle]resourcePath]stringByAppendingFormat:@"/%@/%@",_themeConfiger[_themeName],imageName];

    return [UIImage imageWithContentsOfFile:themePath];

}

//根据textcolorName返回颜色

- (UIColor *)textColorWithTextColorName:(NSString *)textcolorName{

    

    //获取文件路径

    NSString *filePath = [[[NSBundle mainBundle]resourcePath]stringByAppendingFormat:@"/%@/config.plist",_themeConfiger[_themeName]];

    NSDictionary *dicTheme = [NSDictionary dictionaryWithContentsOfFile:filePath];

    

    NSDictionary *dicColor = dicTheme[textcolorName];

   

    //设置透明度

    NSInteger alpha = dicColor.count >= 4 ? [[dicColor objectForKey:@"alpha"] integerValue]: 1;

   

    return [UIColor colorWithRed:[[dicColor objectForKey:@"R"] floatValue] / 255 green:[[dicColor objectForKey:@"G"] floatValue] / 255 blue:[[dicColor objectForKey:@"B"] floatValue] / 255 alpha:alpha];

}


- (void)setThemeName:(NSString *)themeName{

    

    if (_themeName != themeName) {

        _themeName = themeName;

    

        [self initTabBarStyle];

        

        //修改数据

        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

        [defaults setObject:_themeName forKey:KThemeDefaultKey];

        [defaults synchronize];

        //发出通知

        [[NSNotificationCenter defaultCenter]postNotificationName:NotificationTheme object:nil];

    }

}

- (void)initTabBarStyle{

    

    //获取文件路径

    NSString *filePath = [[[NSBundle mainBundle]resourcePath]stringByAppendingFormat:@"/%@/config.plist",_themeConfiger[_themeName]];

    NSDictionary *dicTheme = [NSDictionary dictionaryWithContentsOfFile:filePath];

    

    _tarBarStyle = [[dicTheme objectForKey:@"Statusbar_Style"] integerValue];

}


UI中对于选择主题的处理方法

标签:主题

原文地址:http://10594302.blog.51cto.com/10584302/1695558

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!