【发布时间】:2014-04-25 07:36:44
【问题描述】:
我正在为我的应用程序设置主题,让用户可以在应用程序设置中选择和切换主题。
我有一个三标签标签栏控制器。
选项卡 1 = 时间线;选项卡 2 = 事件和选项卡 3 = 设置,其中三个都是表视图。
用户转到“设置”,单击“主题”单元格并选择一个主题。通过 NSUserDefaults,我得到了根据主题改变的背景图像和导航栏。但是,我正在努力让标签栏图像不断变化。
现在,它已应用在 AppDelegate 中,但这会将其应用于每个场景。
在我的 Timeline TableView 和 viewWillAppear 中,我有:
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];
}
这真的很好用。
但是,如果在上面那个 if 语句的末尾,我添加:
UIImage *tabBackgroundImage = [UIImage imageNamed:@"Orange3tab.png"];
[[UITabBar appearance] setBackgroundImage:tabBackgroundImage];
当我在设置中选择这个主题时,标签栏永远不会改变。
我在网上搜索了一下,发现了这个:
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];
我想为整个应用设置这个。因此,如果用户单击“绿色”主题,则绿色标签栏将应用于整个应用程序。我怎样才能做到这一点?
另外,如果我必须只设置这个 UITabBar 的背景,如上面的代码所示,并且我必须为每个类都这样做,我很高兴,但我如何获得对 [[tabBarController tabBar 的引用]?
在这方面的任何帮助都会非常有帮助。我基本上希望确保选项卡栏主题在选择时保持与背景和导航栏相同的主题。
【问题讨论】:
标签: ios uitabbarcontroller uitabbar uiappearance