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

Jak*_*san 75 tabs colors ios ios7

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

nul*_*ull 207

试试以下内容:

[[UITabBar appearance] setTintColor:[UIColor redColor]];
[[UITabBar appearance] setBarTintColor:[UIColor yellowColor]];
Run Code Online (Sandbox Code Playgroud)

为非活动按钮着色,请将以下代码放入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];
Run Code Online (Sandbox Code Playgroud)

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

迅速:

UITabBar.appearance().tintColor = UIColor.red

tabBarItem.image = UIImage(named: "unselected")?.withRenderingMode(.alwaysOriginal)
tabBarItem.selectedImage = UIImage(named: "selected")?.withRenderingMode(.alwaysOriginal)
Run Code Online (Sandbox Code Playgroud)

  • +1`UIImageRenderingModeAlwaysOriginal` - 我真的需要这个. (4认同)
  • 在iOS7中不推荐使用setFinishedSelectedImage. (2认同)

小智 22

有一种更容易的方法来做到这一点.

只需打开文件检查器并选择"全局色调"即可.

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

另见:

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

  • 全局色调菜单不适用于非故事板笔尖. (8认同)
  • 这将是很好的,除了它在Xcode 5中对我不起作用. (5认同)
  • 不起作用,Xcode 5.1."window.tintColor = [UIColor purpleColor]"确实如此. (3认同)

Öme*_*alı 18

iOS 7.1.1

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

[[UIView appearance] setTintColor:[UIColor whiteColor]];
Run Code Online (Sandbox Code Playgroud)

didFinishLaunchingWithOptionsAppDelegate.

以下代码将在任何viewDidLoad方法中仅更改标签栏色调颜色:

[self.tabBarController.tabBar setTintColor:[UIColor redColor]];
Run Code Online (Sandbox Code Playgroud)


Sof*_*LLC 9

在app delegate didFinishLaunchingWithOptions:

window.tintColor = [UIColor purpleColor];
Run Code Online (Sandbox Code Playgroud)

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


Ruc*_*chi 7

将其写入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];
Run Code Online (Sandbox Code Playgroud)