0

アプリケーションにさまざまなテーマを実装しようとしています。ユーザーは Settingsbundle でさまざまなテーマを選択でき、アプリケーションはユーザーの決定に従ってテーマを表示する必要があります。

でテーマ メソッドを呼び出しますapplicationWillEnterForegroundが、何も変わりません。テーマコードを設定すると- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions、アプリケーションを最初に起動したときにのみテーマが設定され、他のすべての起動では何も変更されません。

バックグラウンド モードを無効にできないため、アプリケーションが動作しません。アプリをクラッシュさせずにテーマメソッドを呼び出す方法はありますか?

アプリケーションがフォアグラウンドに入るたびに呼び出されるテーマコードは次のとおりです。

-(void)themeDecicion {

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSInteger themeMode = [defaults integerForKey:@"themeMode"];
    if (themeMode == 0) {
        themeMode = 1;
    }

    if (themeMode == 1) {
        NSLog(@"automatically");
        NSString *colorString = [DeviceColor frontColor];
        if ([colorString isEqualToString:@"Black"]) {
            [self blackTheme];
        } else if ([colorString isEqualToString:@"White"]) {
            [self whiteTheme];
        } else {
            [self blackTheme];
        }
    } else if (themeMode == 2) {
        [self blackTheme];

    } else if (themeMode == 3) {
        [self whiteTheme];
    } else {
        [self blackTheme];
    }

}

-(void)blackTheme {

    [[UITabBar appearance] setTintColor:[UIColor whiteColor]];
    [[UITabBar appearance] setBarStyle:UIBarStyleBlack];
    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarStyle:UIBarStyleBlackTranslucent];
    [[UISearchBar appearance] setBarStyle:UIBarStyleDefault];
}

-(void)whiteTheme {

    UIColor *defaultColor = [UIColor colorWithRed:(21/255.0) green:(121/255.0) blue:(251/255.0) alpha:1];

    [[UITabBar appearance] setTintColor:defaultColor];
    [[UITabBar appearance] setBarStyle:UIBarStyleDefault];
    [[UINavigationBar appearance] setTintColor:defaultColor];
    [[UINavigationBar appearance] setBarStyle:UIBarStyleDefault];
    [[UISearchBar appearance] setBarStyle:UIBarStyleDefault];

}
4

0 に答える 0