在iOS 7上更改选项卡栏的着色颜色

在iOS 7上更改选项卡栏的着色颜色,ios,ios7,colors,tabs,Ios,Ios7,Colors,Tabs,有没有办法将iOS 7上选项卡栏的色调从默认的带蓝色图标的白色更改为另一种带不同颜色按钮的色调?请尝试以下操作: [[UITabBar appearance] setTintColor:[UIColor redColor]]; [[UITabBar appearance] setBarTintColor:[UIColor yellowColor]]; 要将非活动按钮上色,请将以下代码放入VC的viewDidLoad: UITabBarItem *tabBarItem = [yourTabBar

有没有办法将iOS 7上选项卡栏的色调从默认的带蓝色图标的白色更改为另一种带不同颜色按钮的色调?

请尝试以下操作:

[[UITabBar appearance] setTintColor:[UIColor redColor]];
[[UITabBar appearance] setBarTintColor:[UIColor yellowColor]];
要将非活动按钮上色,请将以下代码放入VC的
viewDidLoad

UITabBarItem *tabBarItem = [yourTabBarController.tabBar.items objectAtIndex:0];

UIImage *unselectedImage = [UIImage imageNamed:@"icon-unselected"];
UIImage *selectedImage = [UIImage imageNamed:@"icon-selected"];

[tabBarItem setImage: [unselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[tabBarItem setSelectedImage: selectedImage];
你需要为所有的Tabbaritem做这件事,是的,我知道这很难看,希望能以更干净的方式来做

Swift:

UITabBar.appearance().tintColor = UIColor.red

tabBarItem.image = UIImage(named: "unselected")?.withRenderingMode(.alwaysOriginal)
tabBarItem.selectedImage = UIImage(named: "selected")?.withRenderingMode(.alwaysOriginal)
///----------------SET TAB BAR COLOR------------------------//

//--------------FOR TAB BAR BUTTON COLOR---------------//
[[UITabBar appearance] setTintColor:[UIColor greenColor]];

//-------------FOR TAB BAR BACKGROUND COLOR------------//
[[UITabBar appearance] setBarTintColor:[UIColor whiteColor]];

有一种更简单的方法可以做到这一点

只需打开文件检查器并选择“全局色调”

您还可以在Interface Builder中设置应用程序的着色颜色。“文件检查器”的“界面生成器文档”部分中的“全局着色”菜单可用于打开“颜色”窗口或选择特定颜色

另见:


应用程序内代理使用以下选项完成启动:

window.tintColor = [UIColor purpleColor];

为应用程序全局设置色调颜色。

iOS 7.1.1

如果有人需要使用全局设置着色颜色:

[[UIView appearance] setTintColor:[UIColor whiteColor]];
AppDelegate
中,使用选项完成启动

下面的代码也将在任何
viewDidLoad
方法中仅更改选项卡栏的着色颜色:

[self.tabBarController.tabBar setTintColor:[UIColor redColor]];

在选项卡栏的视图控制器类中写入以下内容:

// Generate a black tab bar
self.tabBarController.tabBar.barTintColor = [UIColor blackColor];

// Set the selected icons and text tint color
self.tabBarController.tabBar.tintColor = [UIColor orangeColor];

在尝试了所有建议的解决方案后,我找不到任何非常有用的方法

我最后尝试了以下方法:

[self.tabBar setTintColor:[UIColor orangeColor]];
结果很好

我只为每个TabBarItem提供了一个图像。甚至不需要一个精选的图像

我甚至在子视图控制器中使用它来设置不同的颜色:

UIColor *theColorYouWish = ...;
if ([[self.parentViewController class] isSubclassOfClass:[UITabBarController class]]){
    UITabBarController *tbc = (UITabBarController *) self.parentViewController;
    [tbc.tabBar setTintColor:theColorYouWish];
}

您可以将色调颜色和字体设置为setTitleTextattribute:

UIFont *font= (kUIScreenHeight>KipadHeight)?[UIFont boldSystemFontOfSize:32.0f]:[UIFont boldSystemFontOfSize:16.0f];
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName,
                            tintColorLight, NSForegroundColorAttributeName, nil];
[[UINavigationBar appearance] setTitleTextAttributes:attributes];

最终对我起作用的是:

[self.tabBar setTintColor:[UIColor redColor]];
[self.tabBar setBarTintColor:[UIColor yellowColor]];
在Interface Builder中选项卡栏控制器的“属性检查器”中,确保将底部栏设置为不透明选项卡栏:

UITabBar.appearance().tintColor = UIColor.red

tabBarItem.image = UIImage(named: "unselected")?.withRenderingMode(.alwaysOriginal)
tabBarItem.selectedImage = UIImage(named: "selected")?.withRenderingMode(.alwaysOriginal)
///----------------SET TAB BAR COLOR------------------------//

//--------------FOR TAB BAR BUTTON COLOR---------------//
[[UITabBar appearance] setTintColor:[UIColor greenColor]];

//-------------FOR TAB BAR BACKGROUND COLOR------------//
[[UITabBar appearance] setBarTintColor:[UIColor whiteColor]];

现在转到AppDelegate.m文件。查找:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
然后在花括号之间添加此代码以更改选项卡栏按钮和选项卡栏背景的颜色:

UITabBar.appearance().tintColor = UIColor.red

tabBarItem.image = UIImage(named: "unselected")?.withRenderingMode(.alwaysOriginal)
tabBarItem.selectedImage = UIImage(named: "selected")?.withRenderingMode(.alwaysOriginal)
///----------------SET TAB BAR COLOR------------------------//

//--------------FOR TAB BAR BUTTON COLOR---------------//
[[UITabBar appearance] setTintColor:[UIColor greenColor]];

//-------------FOR TAB BAR BACKGROUND COLOR------------//
[[UITabBar appearance] setBarTintColor:[UIColor whiteColor]];

您可能需要对其进行子类化。我从未尝试过,所以我不是100%确定,但这似乎是一个可能的解决方案。谢谢还有一个快速问题,是否有办法对选项卡栏中的非活动按钮着色(未选中时为灰色)?在iOS7中不推荐使用SetFinishedSelecteImage。@非活动按钮的空代码具有forState:uicontrol状态正常,它更改我的应用程序中所有选项卡栏项目(选中和未选中)的颜色。存在其他状态uicontrol状态已选定,但未看到未选定。[[UITabBarItem外观]setTitleTextAttributes..未更改未选定项的颜色,它们保持灰色。对所有选项卡栏项使用uicontrol状态正常,对选定项使用uicontrol状态选定,例如:[[UITabBarItem外观]setTitleTextAttributes:[NSDictionary Dictionary WithObjectsSandKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]forState:UIControlStateSelected];全局着色菜单不适用于非情节提要笔尖。这将非常好,除非它在Xcode 5中对我不起作用。不起作用,Xcode 5.1。“window.tintColor=[UIColor purpleColor]”是的。Interface Builder文档的全局色调设置实际上不允许您为应用程序设置色调。它允许您为故事板设置色调-如果您有多个,您可以混合和匹配,或者在上面的代码中进行设置。真奇怪。我刚刚在iOS 7,Xcode 5.1.1中尝试在故事板中设置色调,但它没有任何作用g为UITabBar创建的故事板。如果使用此选项,仍然可以逐个屏幕覆盖颜色吗?使用第二行的代码,您可以分别覆盖每个屏幕的颜色。这是我发现的唯一一个解决方案,它可以从iOS 7中的VC VDL为当前选项卡项工作。[self.tabBarController.tabBar setTintColor:[UIColor orangeColor]];在Xcode 5.1.1的iOS 7.1上不执行任何操作。即使在AppDelegate中使用_窗口。