在“更多”菜单中更改UITabBar色调颜色

我正在尝试从更多菜单中的图标更改蓝色。 我尝试了几乎所有我在Stack Overflow上找到的东西,但没有任何效果。 我试过这个解决方案 ,但是没有用。

我发现改变颜色的唯一选择是

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

但它改变了应用程序中的所有颜色。

色调颜色没有改变使用UIView外观色调更改色调颜色

代码只是一个带有故事板的新项目,所以我只是在故事板上添加了视图。
谢谢你的帮助。

编辑:我添加代码后:

  UIImage *myImage = [[UIImage imageNamed:@"music.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; self.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"New Title" image:myImage selectedImage:[UIImage imageNamed:@"music.png"]]; 

选择视图时图像会发生变化,但仍然是蓝色。

要做你需要的,你应该通过为每个控制器创建UITabBarItem来使用图像,并添加图像和选定的图像。

请参阅有关UITabBarItem的Apple文档

从@Aaron Brager看其他地方:

  • 如何设置UITabBarItem的未选色,***包括系统项***(iOS7)
  • UITabBarController未选中的图标图像色调

在查看完整代码后进行编辑首先,你的项目中存在很多错误,资产应该在xcassets文件夹中,在视图中,在’super viewDidLoad’之后写入你的代码,等等。

关于您的问题,在FirstViewController的viewDidLoad方法中

 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // Your code start here, not before the super [[UITabBar appearance] setTintColor:[UIColor redColor]]; // Get table view of more new viewController UITableView *view =(UITableView*)self.tabBarController.moreNavigationController.topViewController.view; view.tintColor = [UIColor redColor]; // Change the image color if ([[view subviews] count]) { for (UITableViewCell *cell in [view visibleCells]) { cell.textLabel.textColor = [UIColor redColor]; // Change the text color } } } 

这是Ludovic答案的Swift版本。

请记住,此版本仅更改色调颜色,因为原始答案以非常黑客的方式更改了文本颜色。 要正确更改它,您必须覆盖moreNavigationController及其cellForRowAt函数。

 tabBarController?.tabBar.tintColor = .red if let moreTableView = tabBarController?.moreNavigationController.topViewController?.view as? UITableView { moreTableView.tintColor = .red } 
Interesting Posts