我知道之前也有人问过这个问题,但我在网上搜索还是没有得到任何解决方案。
我引用了以下帖子:
使用tintColor
**.** How can I change the text and icon colors for tabBarItems in iOS 7? 只能更改所选图标的颜色
在这方面,他们已经编写了自己的GozTabBar
How to change the color of unselected tab bar items in iOS 7? 类,该类继承自UIView
当UITabBar
图标处于未选中状态时,我想更改它的默认灰色。
任何帮助都将不胜感激。提前谢谢。
发布于 2014-02-06 16:10:31
我假设您不想使用tintColor更改颜色?另一种选择是使用两个看起来完全相同但颜色不同的图像。一个图像是选中的选项卡,另一个是未选中的。
在您的AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
函数中,尝试如下所示。
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;
// repeat for every tab, but increment the index each time
UITabBarItem *firstTab = [tabBar.items objectAtIndex:0];
// also repeat for every tab
firstTab.image = [[UIImage imageNamed:@"someImage.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
firstTab.selectedImage = [[UIImage imageNamed:@"someImageSelected.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
编辑:对于那些没有将标签栏控制器作为其根视图控制器的人,您可以像这样抓取控制器,其余的代码是相同的。
UITabBarController *tabBarController = self.tabBarController;
发布于 2014-05-10 00:48:41
如果您已经使用Storyboard配置了选项卡栏图像,只需在第一个视图的ViewDidLoad中调用此方法:
-(void) configTabBar
{
UITabBarController *tabBarController = [self tabBarController];
UITabBar *tabBar = tabBarController.tabBar;
for (UITabBarItem *tab in tabBar.items) {
tab.image = [tab.image imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];
tab.selectedImage = [tab.image imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];
}
}
发布于 2014-09-19 23:24:03
[[UITabBar appearance] setTintColor:[UIColor colorWithRed:252/255.0 green:218/255.0 blue:49/255.0 alpha:1.0]];
tabBarItem1.image = [[UIImage imageNamed:@"home_icon.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem1.selectedImage = [UIImage imageNamed:@"home_icon_selected.png"];
[[UITabBar appearance] setBackgroundColor:[UIColor colorWithRed:15/255.0 green:85/255.0 blue:160/255.0 alpha:1.0]];
// Change the title color of tab bar items
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], NSForegroundColorAttributeName,
nil] forState:UIControlStateNormal];
UIColor *titleHighlightedColor = [UIColor colorWithRed:252/255.0 green:218/255.0 blue:49/255.0 alpha:1.0];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
titleHighlightedColor, NSForegroundColorAttributeName,
nil] forState:UIControlStateHighlighted]
https://stackoverflow.com/questions/21596515
复制相似问题