简体   繁体   English

UITabBarController最初高亮显示所有选项卡栏项目图像

[英]UITabBarController initially highlights all tab bar item images

I'm programmatically instantiating a UITabBarController that will manage 2 view controllers, and then setting it as the rootViewController . 我正在以编程方式实例化将管理2个视图控制器的UITabBarController ,然后将其设置为rootViewController However when the views appear, it highlights all the tab item's images (although the text is properly highlighted). 但是,当视图出现时,它将突出显示选项卡项目的所有图像(尽管文本已正确突出显示)。 No matter what I set to the selectedIndex the images will all appear highlighted. 无论我为selectedIndex设置什么,图像都将突出显示。 Only when you tap on the tab bar items does it actually toggle the highlighted state on the images. 仅当您点击选项卡栏项目时,它才实际切换图像上的突出显示状态。 What's going on here? 这里发生了什么?

Code: 码:

UITabBarController *tabController = [[UITabBarController alloc] init];
UIStoryboard *storyboard = [self storyboard];
OGVideoStreamViewController *questionsController = [storyboard instantiateViewControllerWithIdentifier:@"OGVideoStreamViewController"];
questionsController.isQuestion = YES;
OGVideoStreamViewController *answersController = [storyboard instantiateViewControllerWithIdentifier:@"OGVideoStreamViewController"];
answersController.isQuestion = NO;
OGMatchesViewController *matchesController = [[OGMatchesViewController alloc] initWithNibName:@"OGMatchesViewController" bundle:nil];

questionsController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Questions" image:[UIImage imageNamed:@"Tab Icon - Questions"] tag:0];
answersController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Answers" image:[UIImage imageNamed:@"Tab Icon - Answers"] tag:1];
matchesController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Inbox" image:[UIImage imageNamed:@"Tab Icon - Inbox"] tag:2];

[tabController setViewControllers:@[questionsController, answersController, matchesController] animated:NO];
tabController.selectedViewController = questionsController;


[[UIApplication sharedApplication] keyWindow].rootViewController = tabController;

在此处输入图片说明

I've had the same problem and it was due to me calling: 我遇到了同样的问题,这是由于我打电话给我的:

[UIView appearance].tintColor = [UIColor colorWithRed:1.000
                        green:0.793
                         blue:0.236
                        alpha:1.000];

I called it in my AppDelegate, so i could change it to the following: 我在AppDelegate中调用了它,因此可以将其更改为以下内容:

self.window.tintColor = [UIColor colorWithRed:1.000
                    green:0.793
                     blue:0.236
                    alpha:1.000];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 检测UITabBarController的选项卡栏项目更改 - Detect Tab bar item change for UITabBarController 以编程方式选择选项卡栏项(不使用UITabBarController) - Select a tab bar item programmatically (not using UITabBarController) 没有标签栏项目的UITabBarController中的UIViewController - UIViewController in a UITabBarController without tab bar item UITabBarController添加不带标签栏项目的viewcontroller - UITabBarController add viewcontroller without tab bar item 从UITabBarController场景中删除选项卡栏项 - Remove tab bar item from a UITabBarController scene 如何在没有视图控制器的情况下将标签栏项添加到UITabBarController? - How to add a tab bar item to UITabBarController without a view controller? 共享按钮作为 UITabBarController 上的标签栏项目,没有关联的控制器 - share button as tab bar item on UITabBarController with no controller associated 将控制器添加到UITabBarController,而标签栏中没有出现新项目 - Add controller to UITabBarController without new item appearing in the tab bar 带有两个图像的标签栏项目 - Tab bar item with two images 将UINavigationController添加到UITabBarController,而不显示所有视图中的Tab Bar - Add UINavigationController to UITabBarController without Tab Bar showing up in all views
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM