【问题标题】:Theming my iPhone App with a new background, navigation bar image and tab bar image使用新背景、导航栏图像和标签栏图像为我的 iPhone 应用程序设置主题
【发布时间】: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


    【解决方案1】:

    这已在我的 viewWillAppear 中使用以下代码修复:

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

    【讨论】:

      猜你喜欢
      • 2012-02-13
      • 2015-06-19
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多