我正在尝试从更多菜单中的图标更改蓝色.我尝试了几乎我在Stack Overflow上找到的所有内容,但没有任何效果. 我试过这个 solution,但是没有用. 我发现改变颜色的唯一选择是 [[UIView appearan
我试过这个 solution,但是没有用.
我发现改变颜色的唯一选择是
[[UIView appearance] setTintColor:[UIColor redColor]];
但它改变了应用程序中的所有颜色.
代码只是一个带有故事板的新项目,所以我只是在故事板上添加了视图.
谢谢你的帮助.
编辑:我添加代码后:
UIImage *myImage = [[UIImage imageNamed:@"music.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; self.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"New Title" image:myImage selectedImage:[UIImage imageNamed:@"music.png"]];
选择视图时图像会发生变化,但仍然是蓝色.
要做你需要的,你应该通过为每个控制器创建UITabBarItem来使用图像,并添加图像和选定的图像.见Apple Documentation about UITabBarItem
另外看看@Aaron Brager:
> How to set UITabBarItem’s unselected tint, ***including system items*** (iOS7)
> UITabBarController unselected icon image tint
在查看完整代码后进行编辑
首先,你的项目有很多错误,资产应该在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
}
}
}
