0

I am in the process of theming my application, giving users the choice of selecting and switching between themes in the App Settings.

I have a three-tabbed Tab Bar Controller.

Tab 1 = Timeline; Tab 2 = Events and Tab 3 = Settings where all three are Table Views.

The user goes to Settings, clicks on the "Themes" cell and selects a theme. Through NSUserDefaults, I've got the background image and the navigation bar changing according to the theme. However, I'm struggling with getting the Tab Bar image to change consistently.

Right now, it's applied in the AppDelegate, but that applies it to every scene.

In my Timeline TableView and in the viewWillAppear, I have:

else if ([self.selectedTheme isEqualToString:@"Twirl"])
{
    ThemeManager *themeManager = [ThemeManager sharedManager];
    themeManager.backgrounds = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ReddishBlack.png"]];
    self.tableView.backgroundView = themeManager.backgrounds;
    UIImage *navBackgroundImage = [UIImage imageNamed:@"ReddishBlackNav.png"];

    [[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];

}

That works really well.

However, if at the end of that if statement above, I add:

UIImage *tabBackgroundImage = [UIImage imageNamed:@"Orange3tab.png"];
[[UITabBar appearance] setBackgroundImage:tabBackgroundImage];

When I select this theme in the settings, the tab bar never changes.

I did a bit of searching online and came across this:

UIImage *tabBackground = [[UIImage imageNamed:@"tabBarBackground.jpg"] 
                          resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
// Set background for all UITabBars
[[UITabBar appearance] setBackgroundImage:tabBackground];
// Set background for only this UITabBar
[[tabBarController tabBar] setBackgroundImage:tabBackground];

I want to set this for the entire app. So if the user clicks on the "Green" theme, then the green tab bar gets applied to the entire app. How can I achieve this?

Also, if I have to set the background of only this UITabBar as seen in the code above and I have to do this for every class, I'm happy to, but how do I get a reference to [[tabBarController tabBar]?

Any assistance on this would be so helpful. I'm basically looking to ensure the Tab bar theme maintains the same theme as the background and navigation bar when selected.

pckill
  • 3,709
  • 36
  • 48
amitsbajaj
  • 1,304
  • 1
  • 24
  • 59

1 Answers1

0

This has been fixed with the following code in my viewWillAppear:

    UIImage *tabBackground = [[UIImage imageNamed:@"purplytab.png"]
                              resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    [self.tabBarController.tabBar setBackgroundImage:tabBackground];
amitsbajaj
  • 1,304
  • 1
  • 24
  • 59