我正在尝试更改更多菜单中图标的蓝色。我几乎尝试了在 Stack Overflow 上找到的所有内容,但没有任何效果。 我试过这个solution , 但不工作。
我发现改变颜色的唯一选择是
[[UIView appearance] setTintColor:[UIColor redColor]];
但它会更改应用中的所有颜色。
代码只是一个带有 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:
- How to set UITabBarItem's unselected tint, ***including system items*** (iOS7)
- UITabBarController unselected icon image tint
看到完整代码后编辑 首先你的项目中有很多错误, 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/