我在我的 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/