【发布时间】:2013-02-05 08:49:04
【问题描述】:
在我的应用程序中,我想更改标签栏控制器的颜色,如何在 ios6 中为标签栏控制器分配自定义颜色,例如导航栏?谁能给我一些参考?
【问题讨论】:
-
您想应用自定义标签栏图标更改吗?如果是,那么您需要创建自定义 TabBar。
标签: iphone ios6 uitabbarcontroller
在我的应用程序中,我想更改标签栏控制器的颜色,如何在 ios6 中为标签栏控制器分配自定义颜色,例如导航栏?谁能给我一些参考?
【问题讨论】:
标签: iphone ios6 uitabbarcontroller
将此放在应用委托上:
UITabBarController *tabBarController = (UITabBarController *) self.window.rootViewController;
tabBarController.view.tintColor = [UIColor redColor];
这比第一个答案更好,因为它还改变了编辑视图的色调。
【讨论】:
您可以按照说明使用 setTintColor 选项
[tabbarController.tabBar setTintColor:[UIColor greenColor]];
或者你可以设置背景图片
[tabbarController.tabBar setBackgroundImage:[UIImage imageNamed:@"tab_bg.png"];
如果您的 TabBarController 是在 AppDelegate 中定义的,您可能需要额外的编码才能访问它。
首先设置背景图片
[[[[(UITabBarController *)[[(AppDelegate *)[UIApplication sharedApplication].delegate window] rootViewController]tabBar]setBackgroundImage:[UIImage imageNamed:@"tab_bg.png"]]]];
如果需要,第二次设置 tintcolor
[[[[(UITabBarController *)[[(AppDelegate *)[UIApplication sharedApplication].delegate window] rootViewController]tabBar]setTintColor:[UIColor redColor]]]];
不要忘记导入您的 AppDelegate.h 文件。
【讨论】:
你可以使用这个调用
tabbarController.tabBar.tintColor = [UIColor redColor];
【讨论】:
只改变tabBar的颜色,你可以这样实现:
tabbarController.tabBar.tintColor = [UIColor redColor];
但是,更重要的是,您需要创建自定义 TabBar,并可以使用它来更改颜色、自定义标签栏图标等。
希望对你有帮助。
干杯。
【讨论】:
对我有用的方法(在 iOS6 中测试)是:
[[UITabBar appearance]setTintColor:[UIColor redColor]];
在 AppDelegate.h 文件中的方法 application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 中。如果它仍然是实际的,试试这个。我看到这个问题仍然没有解决。
【讨论】: