在iOS 7上更改标签栏色调颜色

时间:2013-09-13 20:57:10

标签: ios ios7 colors tabs

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

9 个答案:

答案 0 :(得分:206)

尝试以下方法:

[[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];

你需要为所有的tabBarItems做这个,是的,我知道它很难看,并希望更清洁地做到这一点。

<强>夫特:

UITabBar.appearance().tintColor = UIColor.red

tabBarItem.image = UIImage(named: "unselected")?.withRenderingMode(.alwaysOriginal)
tabBarItem.selectedImage = UIImage(named: "selected")?.withRenderingMode(.alwaysOriginal)

答案 1 :(得分:22)

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

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

  

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

另见:

https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/AppearanceCustomization.html

答案 2 :(得分:16)

iOS 7.1.1

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

[[UIView appearance] setTintColor:[UIColor whiteColor]];

didFinishLaunchingWithOptions的{​​{1}}。

此外,代码下方只会更改任何AppDelegate方法中的标签栏色调颜色:

viewDidLoad

答案 3 :(得分:9)

在app delegate didFinishLaunchingWithOptions:

window.tintColor = [UIColor purpleColor];

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

答案 4 :(得分:5)

将此内容写入Tab栏的View Controller类:

// 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];

答案 5 :(得分:2)

最终对我有用的是:

[self.tabBar setTintColor:[UIColor redColor]];
[self.tabBar setBarTintColor:[UIColor yellowColor]];

答案 6 :(得分:1)

&#34; 属性检查器&#34; Interface Builder 中的标签栏控制器,确保您的底栏设置为不透明标签栏:

Choose Opaque

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

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

然后在花括号之间添加此代码,以更改标签栏按钮和标签栏背景的颜色:

///----------------SET TAB BAR COLOR------------------------//

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

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

答案 7 :(得分:0)

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

我终于尝试了以下内容:

[self.tabBar setTintColor:[UIColor orangeColor]];

完美无缺。

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

我甚至在Child-ViewControllers中使用它来设置不同的TintColors:

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

答案 8 :(得分:-3)

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

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];
相关问题