ios - 在更多菜单中更改 UITabBar 色调颜色

标签 ios uitabbar tintcolor

我正在尝试更改更多菜单中图标的蓝色。我几乎尝试了在 Stack Overflow 上找到的所有内容,但没有任何效果。 我试过这个solution , 但不工作。

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

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

但它会更改应用中的所有颜色。

tint color not changed tint colour changed using UIView appearance tint color

代码只是一个带有 Storyboard的新项目,所以我只是在 Storyboard上添加了 View 。
感谢您的帮助。

编辑:添加代码后:

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

当 View 被选中时,图像发生了变化,但它仍然是蓝色的。

最佳答案

要执行您需要的操作,您应该通过为每个 Controller 创建 UITabBarItem 并添加图像和选定图像来使用图像。

参见 Apple Documentation about UITabBarItem

否则看这里,来自@Aaron Brager:

看到完整代码后编辑 首先你的项目中有很多错误, Assets 应该在xcassets文件夹中, View didload在'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

        }
    }
}

关于ios - 在更多菜单中更改 UITabBar 色调颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26105507/

相关文章:

ios - 收到适用于 IOS 的 Opencv 库的错误

ios - 更改 UITabBarController 中选项卡的宽度以调整第六个选项卡

ios - 当图像是 UITabBar 的选择时使用原始图像颜色的优雅方法

ios - 当 UITabbar 是半透明的并且 UIViewController 没有扩展到 tabbar 后面时,uitabbar 看起来像是覆盖了一个黑色 View

ios - 在 iOS 中呈现弹出窗口时如何避免按钮色调颜色变化?

iOS:tint 颜色实际上有什么作用?

objective-c - 使用 CHCSVWriter 保存 CSV 文件

ios - 使用 AutoLayout/UIScrollView 设置约束时了解 UIView 高度

ios - 面向协议(protocol)编程

iphone - 我可以淡化/动画 UIToolbar 的 tintColor 吗?