0

I am trying to implement different themes to my application. The user can select the different themes in the Settingsbundle, then the application should display the theme according to the user decision.

I call the theming method in applicationWillEnterForeground, but then nothing will change. When I set the theming code in - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions It only themes my application the first time i launch it, every other launch it wont change anything.

I cant disable the background mode, cause then my application wont work. Any idea, how I can call the theming method without crashing my app?

Here is my theming code which should be called every time the application entered the foreground:

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

}
David Gölzhäuser
  • 3,525
  • 8
  • 50
  • 98

0 Answers0