ios - 为 ios 中的不同 View Controller 设置不同的标签栏外观

标签 ios objective-c xcode ios7 tabbar

我有一个基于标签栏的应用程序。

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

相关文章:

ios - UITextField 和 UIButton 在 signOut segue swift 后无响应

ios - 加载视频 ID 时 YouTubePlayer pod 崩溃

ios - 构建 Archive 时未找到 Apple 框架

iphone - 当我从 Xib 文件加载自定义 UITableViewCells 时发生泄漏?

ios - drawViewHierachyInRect 以错误的方向绘制 iPad

iphone - UISegmentedControl的选定段

没有服务器代码的 iOS cron 作业

ios - UITableView header 内容器 View 的自动布局约束在不同设备上被破坏

ios - 检测是否在越狱的 iDevice 中安装/卸载了另一个应用程序

iphone - 视网膜图像的实际像素尺寸 (iOS)