溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

UI中對(duì)于選擇主題的處理方法

發(fā)布時(shí)間:2020-07-27 17:40:06 來源:網(wǎng)絡(luò) 閱讀:245 作者:ladispartion1 欄目:開發(fā)技術(shù)

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

        

        //取得狀態(tài)欄狀態(tài)

        [self initTabBarStyle];

    }

    return self;

}


//創(chuàng)建單例

+ (ThemeManager *)shareThemeManage{

    

    static dispatch_once_t onceToken;

    dispatch_once(&onceToken, ^{

        themeManage = [[ThemeManager alloc]init];

    });

    return themeManage;

}



//根據(jù)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];

}

//根據(jù)textcolorName返回顏色

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

    

    //獲取文件路徑

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

    NSDictionary *dicTheme = [NSDictionary dictionaryWithContentsOfFile:filePath];

    

    NSDictionary *dicColor = dicTheme[textcolorName];

   

    //設(shè)置透明度

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

        

        //修改數(shù)據(jù)

        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

        [defaults setObject:_themeName forKey:KThemeDefaultKey];

        [defaults synchronize];

        //發(fā)出通知

        [[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];

}


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI