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

4
我正在尝试更改“更多”菜单中图标的蓝色颜色。我尝试了Stack Overflow上找到的几乎所有方法,但都没有用。我尝试了这个解决方案,但不起作用。
我发现唯一可以更改颜色的选项是:
[[UIView appearance] setTintColor:[UIColor redColor]];

但是它会改变应用程序中所有颜色。

未更改的色调颜色 使用UIView外观色调颜色更改的色调颜色

这段代码只是一个带有Storyboard的新项目,因此我只是在故事板上添加了视图。
谢谢您的帮助。

编辑:我添加了代码后:

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

视图被选中时图像会发生变化,但它仍然是蓝色的。
3个回答

7
为了达到您的需求,您应该通过为每个控制器创建UITabBarItem并添加一个图像和一个选定的图像来使用图像。
请参见Apple有关UITabBarItem的文档
否则,请查看@Aaron Brager的内容: 在查看完整代码后进行编辑 首先,在您的项目中有许多错误,资源应位于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

        }
    }
}

谢谢回复,我尝试了建议中的代码,但仍然无法正常工作。我猜我做错了什么。如果您能看一下,我附上了完整的代码。 - varu
@varu,我刚刚更新了我的答案。我没明白你在使用Storyboard! - Ludovic
我在一个大型2010年开始的项目中遇到了颜色渲染问题,并不得不修复图标的问题。我为StackOverflow创建了一个新项目。 非常感谢您的帮助,我非常感激。我还有很多要学习 :) - varu

2
这是Ludovic's answer的Swift版本。
请注意,此版本仅更改了色调颜色,因为原始答案使用了非常巧妙的方式更改了文本颜色。要正确更改它,您必须重写moreNavigationController及其cellForRowAt函数。
tabBarController?.tabBar.tintColor = .red

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

0

改变这个按钮的颜色

    moreNavigationController.navigationBar.tintColor = .white

enter image description here


有没有办法隐藏这个“上面的编辑”按钮? - coders

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接