在“更多”菜单中更改UITabBar色调颜色 [英] Change UITabBar tint colors in the More menu

查看:94
本文介绍了在“更多”菜单中更改UITabBar色调颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



否则从@Aaron Brager看这里:





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



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

   - (void)viewDidLoad {
[super viewDidLoad];
//加载视图后进行任何其他设置,通常是从笔尖。
//你的代码从这里开始,而不是超级
[[UITabBar外观] setTintColor:[UIColor redColor]];

//获取更多新viewController的表视图
UITableView * view =(UITableView *)self.tabBarController.moreNavigationController.topViewController.view;

view.tintColor = [UIColor redColor]; //更改图像颜色

if([[view subviews] count]){
for(UITableViewCell * cell in [view visibleCells]){
cell.textLabel.textColor = [UIColor redColor]; //更改文字颜色

}
}
}


I'm trying to change the blue colour from icons in the more menu. I tried almost everything I found on Stack Overflow, but nothing worked. I tried this solution, but is not working.

The only option I found to change the colour was

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

but it changes all colours in the app.

The code is just a new project with storyboard, so I just added the views on the storyboard.
Thanks for helping.

Edit: After I added the code:

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

The image is changed when the view is selected, but it's still blue.

解决方案

To do what you need, you should use images by creating UITabBarItem for each controller and add an image and a selected image.

See Apple Documentation about UITabBarItem

Otherwise looks here, from @Aaron Brager :

Edit after seing the full code First there is many mistakes in your project, assets should be in xcassets folder, in view didload write your code after the 'super viewDidLoad]', etc.

About your problem, in your viewDidLoad method in the FirstViewController

- (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

        }
    }
}

这篇关于在“更多”菜单中更改UITabBar色调颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆