我有一个基于标签栏的应用程序。
我已经在我的 applicationDidFinishLaunchingWithOptions
中使用下面显示的代码设置了标签栏的背景图像。
UIImage* tabBarBackground = [UIImage imageNamed:@"tabbarbottom2.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
我在 Storyboard中这样做。
现在,有了这段代码。我的 Tabbar 的背景图片正在设置并且运行良好。
但是我想为tabbar的不同 View Controller 设置不同的背景。
我已经搜索了很多,但找不到这样做的方法。
我纠结了好久。
请帮我解决这个问题。
提前致谢。
最佳答案
您始终可以覆盖 viewDidLoad
中的默认值。如果你想为不同的标签栏 Controller 设置背景图像,你必须继承 UITabBarController 并将以下内容添加到 viewDidLoad。
[self.tabBar setBackgroundImage:[UIImage imageNamed:@"tabbarForThisController.png"]];
如果你想要不同的图片取决于你必须添加的所选标签
[self.tabBarController.tabBar setBackgroundImage:[UIImage imageNamed:@"tabBarForThisTab.png"]];
到所选选项卡的 View Controller 中的 viewDidLoad
。
关于ios - 为 ios 中的不同 View Controller 设置不同的标签栏外观,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25119842/