ios - UITabBar 自定义背景图像应用于一个 View Controller 而不是 AppDelegate

标签 ios iphone uitabbar uiappearance

我在我的 iPhone 应用程序中使用主题。我在选项卡栏(时间轴和设置)中有两个选项卡,当用户转到第二个选项卡(设置)时,在设置中选择主题并选择一个主题,这会为第一个表格 View 的背景图像和导航栏设置样式第一个选项卡(时间轴)中的 Controller 。这行得通。

我想用标签栏实现同样的功能,所以标签栏随着背景图片和导航栏的变化而变化。

在我的时间线 TableView 中,我将以下代码放在 viewWillAppear 中:

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

但是,标签栏永远不会改变。更改选项卡栏的唯一方法是在 AppDelegate 中,但随后会在所有地方更改它。我需要允许用户选择一个主题并进行相应更改,因此我需要在每个 View Controller 的基础上进行更改,与导航栏的方式完全相同。

在这个时间轴 TableView 的 viewWillAppear 中,我将导航栏设置为:

UIImage *navBackgroundImage = [UIImage imageNamed:@"Purplepinknav.png"];
[[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];

这总是有效的。这不适用于标签栏,但是使用上面的代码。

编辑:我已将 apperanceWhenContainedIn 添加到 viewWillAppear:

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

[UITabBar appearanceWhenContainedIn:[UITabBar class], [UITabBar class], nil];

但这似乎并没有做任何事情。

我该如何解决这个问题?任何帮助将不胜感激。

最佳答案

您可以尝试对 UIAppearance 代理调用进行改进...

+ (id)appearanceWhenContainedIn:(Class <UIAppearanceContainer>)ContainerClass,...

仅当它包含在特定 View Controller 子类中时,才将 UIAppearance Proxy 兼容对象的外观设置为提供的值。

关于ios - UITabBar 自定义背景图像应用于一个 View Controller 而不是 AppDelegate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22486023/

相关文章:

iphone - 在标签栏上设置背景图像

ios - 当 UITabBar 不是 rootViewController 时,如何以编程方式将 UITabBar 与带有 NIB 的不同 ViewController 链接

iphone - 计算 map 图钉

iphone - Apple ID 可以访问吗?

ios - 我在 JS 中看不到任何 iOS native 模块

ios - dequeueReusableCell 中的 SIGABRT 错误(使用自定义 UITableViewCell 时带有标识符 :),

iphone - 有没有办法从 ios 中的 mp3 中提取嵌入的图像数据

ios - 如何让按钮返回到指定的 View Controller

c++ - Xcode 中关于 OpenCV 的链接错误

ios - 稍后调用 tableView cellForRowAtIndexPath