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

发布时间:2020-07-27 17:40:06 作者:ladispartion1
来源:网络 阅读:243

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

}



//根据p_w_picpathName返回图片

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

    

    //获取文件路径

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

    return [UIImage p_w_picpathWithContentsOfFile: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];

}


推荐阅读:
  1. 使用jQuery UI插件实现切换主题功能——经验小结
  2. Element UI框架中巧用树选择器的实现

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

主题 中对 处理方法

上一篇:Windows Azure Pack 快速部署(1)AD环境准备及Sql Ser安装

下一篇:Docker 获取容器镜像报错

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》