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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18795117/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 01:10:39  来源:igfitidea点击:

Change tab bar tint color on iOS 7

iosios7colorstabs

提问by Jake Chasan

Is there a way to change the tint of a tab bar on iOS 7 from the default white with blue icons to another color tint with different color buttons?

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

回答by Tarek Hallak

Try the below:

试试下面的:

[[UITabBar appearance] setTintColor:[UIColor redColor]];
[[UITabBar appearance] setBarTintColor:[UIColor yellowColor]];

To tint the non activebuttons, put the below code in your VC's viewDidLoad:

为非活动按钮着色,请将以下代码放入您的 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];

You need to do this for all the tabBarItems, and yes I know it is ugly and hope there willbe cleaner way to do this.

您需要为所有的tabBarItems做到这一点,是的,我知道这是丑陋的,希望有是更清洁的方式来做到这一点。

Swift:

迅速:

UITabBar.appearance().tintColor = UIColor.red

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

回答by herdi

There is an much easier way to do this.

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

Just open the file inspector and select a "global tint".

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

You can also set an app's tint color in Interface Builder. The Global Tint menu in the Interface Builder Document section of the File inspector lets you open the Colors window or choose a specific color.

您还可以在 Interface Builder 中设置应用程序的色调颜色。文件检查器的 Interface Builder Document 部分中的 Global Tint 菜单可让您打开 Colors 窗口或选择特定颜色。

Also see:

另见:

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

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

回答by ?mer Faruk Almal?

iOS 7.1.1

iOS 7.1.1

If someone is going to need to use globally setting tint color:

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

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

In didFinishLaunchingWithOptionsof AppDelegate.

didFinishLaunchingWithOptionsAppDelegate

Also below code will change only tab bar tint color in any viewDidLoadmethod:

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

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

回答by Sofi Software LLC

In app delegate didFinishLaunchingWithOptions:

在应用程序委托中 didFinishLaunchingWithOptions:

window.tintColor = [UIColor purpleColor];

sets the tint color globally for the app.

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

回答by Ruchi

Write this in your View Controller class of your Tab Bar:

在你的 Tab Bar 的 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];

回答by Javier Calatrava Llavería

What finally worked for me was:

最终对我有用的是:

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

回答by Javier Calatrava Llavería

In "Attributes Inspector" of your Tab Bar Controllerwithin Interface Buildermake sure your Bottom Bar is set to Opaque Tab Bar:

在“属性检查器”你的标签栏控制器Interface Builder中确保你的底栏设置为不透明标签栏:

Choose Opaque

选择不透明

Now goto your AppDelegate.mfile. Find:

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

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

And then add this code between the curly braces to change the colors of both the tab bar buttons and the tab bar background:

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

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

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

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

回答by dfinki

After trying out all the suggested solutions, I couldn't find any very helpful.

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

I finally tried the following:

我终于尝试了以下方法:

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

which worked out perfectly.

效果很好。

I only provided one image for every TabBarItem. Didn't even need a selectedImage.

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

I even used it inside the Child-ViewControllers to set different TintColors:

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

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

回答by user3737678

You can set your tint color and font as setTitleTextattribute:

您可以将色调颜色和字体设置为 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];