var*_*aru 3 uitabbar tintcolor ios
我正在尝试从更多菜单中的图标更改蓝色.我尝试了几乎我在Stack Overflow上找到的所有内容,但没有任何效果.我试过这个解决方案,但是没有用.
我发现改变颜色的唯一选择是
[[UIView appearance] setTintColor:[UIColor redColor]];
Run Code Online (Sandbox Code Playgroud)
但它改变了应用程序中的所有颜色.

代码只是一个带有故事板的新项目,所以我只是在故事板上添加了视图.
谢谢你的帮助.
编辑:我添加代码后:
UIImage *myImage = [[UIImage imageNamed:@"music.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
self.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"New Title" image:myImage selectedImage:[UIImage imageNamed:@"music.png"]];
Run Code Online (Sandbox Code Playgroud)
选择视图时图像会发生变化,但仍然是蓝色.
要做你需要的,你应该通过为每个控制器创建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
}
}
}
Run Code Online (Sandbox Code Playgroud)