如果我们有超过 5 个选项卡栏项目,如何设置除默认蓝色之外的选项卡栏项目颜色?

发布于 2024-10-06 09:00:59 字数 217 浏览 0 评论 0原文

我在我的应用程序中使用带有超过 5 个颜色为绿色(即自定义)的选项卡项目的选项卡栏控制器。正如我们所知,第 5 个、第 6 个选项卡栏项目由 MoreViewController 自动处理。 我的问题是 1)如果我选择“更多选项卡栏”项目,我确实得到了蓝色项目。 2)如果我从“更多选项卡栏”项目切换到上一个选项卡栏项目,我也确实将项目颜色设置为蓝色。 那么,如何使选项卡栏项目在两种情况下都颜色为绿色呢?

I am using tab bar controller with more than 5 tab items with color as green (ie customized) in my application. As we know 5th, 6th.. tabbar items are handled automatically by MoreViewController.
My question is
1) if I select the More Tabbar item, blue color item I did get.
2) If I switch from More Tabbar item into previous one, I also did get the items color as blue.
So, how to make the tabbar items color as green in both cases?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不喜欢何必死缠烂打 2024-10-13 09:00:59

苹果文档中没有解决这个问题。我以我自己的带有自定义按钮的伪造标签栏结束。

In apple documentation there is no solution for this. I ended with my own faked tabbar with customized buttons.

单挑你×的.吻 2024-10-13 09:00:59
buddy  you have 2 choices 

1. u take 2 image for every tabbar 1st disable tile 2nd show enable time



   self.window.backgroundColor =[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]]; //[UIColor blackColor];

    tabBarController = [[UITabBarController alloc] init];
    [tabBarController setDelegate: self];
   // [tabBarController.tabBar setDelegate:self];
    //tabBarController = [[UITabBarController alloc] init];
    tabBarController.tabBar.tintColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]];
    //tabBarController.tabBarItem.title=[UIColor whiteColor];
    //[[UITabBar appearance] setSelectedImageTintColor:[UIColor redColor]];
    //[[UITabBar appearance] setBackgroundColor:[UIColor whiteColor]];
    //tabBarController.tabBar.backgroundColor = [UIColor whiteColor];
    NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:7];
    Login *home = [[Login alloc] initWithNibName:@"Login" bundle:nil];
    localNavController = [[UINavigationController alloc] initWithRootViewController:home];
    //localNavController.tabBarItem.image = [UIImage imageNamed:@"Central.png"];
    localNavController.tabBarItem.title=@"Central";
    [localViewControllersArray addObject:localNavController];
    PuckDisplay *puck=[[PuckDisplay alloc]initWithNibName:@"Display" bundle:nil];
    localNavController = [[UINavigationController alloc] initWithRootViewController:uck];
    //localNavController.tabBarItem.image = [UIImage imageNamed:@"Display.png"];
    localNavController.tabBarItem.title=@" Display";
    [localViewControllersArray addObject:localNavController];

    PhotoBooth *photo=[[PhotoBooth alloc]initWithNibName:@"Booth" bundle:nil];
    localNavController = [[UINavigationController alloc] initWithRootViewController:photo];
    //localNavController.tabBarItem.image = [UIImage imageNamed:@"Booth.png"];
    localNavController.tabBarItem.title=@"Booth";
    [localViewControllersArray addObject:localNavController];

    More *more=[[More alloc]initWithNibName:@"More" bundle:nil];
    localNavController = [[UINavigationController alloc] initWithRootViewController:more];
    //localNavController.tabBarItem.image = [UIImage imageNamed:@"home.png"];
    localNavController.tabBarItem.title=@"More";
    [localViewControllersArray addObject:localNavController];

    tabBarController.viewControllers = localViewControllersArray;
    [[UITabBarItem appearance] setTitleTextAttributes:
    [NSDictionary dictionaryWithObjectsAndKeys:
    [UIColor grayColor], UITextAttributeTextColor, 
    [UIColor grayColor], UITextAttributeTextShadowColor, 
    [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, 
    [UIFont fontWithName:@"Helvetica" size:0.0], UITextAttributeFont, nil] 
                                             forState:UIControlStateNormal];
    UITabBarItem *tabBarItem1 = [[self.tabBarController.tabBar items] objectAtIndex:0];
    [tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"CentralA.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"Central.png"]];
    UITabBarItem *tabBarItem2 = [[self.tabBarController.tabBar items] objectAtIndex:1];
    [tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:@"DisplayA.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"Display.png"]];
    UITabBarItem *tabBarItem3 = [[self.tabBarController.tabBar items] objectAtIndex:2];
    [tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:@"BoothA.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"Booth.png"]];
    UITabBarItem *tabBarItem4 = [[self.tabBarController.tabBar items] objectAtIndex:3];
    [tabBarItem4 setFinishedSelectedImage:[UIImage imageNamed:@"moreA.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"more.png"]];














2. if u want only change tabbar color then change tabbar tin color
self.tabBarController.tabBar.tintColor = [UIColor colorWithRed:(157/255.0) green:(33/255.0) blue:(33/255.0) alpha:1];
buddy  you have 2 choices 

1. u take 2 image for every tabbar 1st disable tile 2nd show enable time



   self.window.backgroundColor =[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]]; //[UIColor blackColor];

    tabBarController = [[UITabBarController alloc] init];
    [tabBarController setDelegate: self];
   // [tabBarController.tabBar setDelegate:self];
    //tabBarController = [[UITabBarController alloc] init];
    tabBarController.tabBar.tintColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]];
    //tabBarController.tabBarItem.title=[UIColor whiteColor];
    //[[UITabBar appearance] setSelectedImageTintColor:[UIColor redColor]];
    //[[UITabBar appearance] setBackgroundColor:[UIColor whiteColor]];
    //tabBarController.tabBar.backgroundColor = [UIColor whiteColor];
    NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:7];
    Login *home = [[Login alloc] initWithNibName:@"Login" bundle:nil];
    localNavController = [[UINavigationController alloc] initWithRootViewController:home];
    //localNavController.tabBarItem.image = [UIImage imageNamed:@"Central.png"];
    localNavController.tabBarItem.title=@"Central";
    [localViewControllersArray addObject:localNavController];
    PuckDisplay *puck=[[PuckDisplay alloc]initWithNibName:@"Display" bundle:nil];
    localNavController = [[UINavigationController alloc] initWithRootViewController:uck];
    //localNavController.tabBarItem.image = [UIImage imageNamed:@"Display.png"];
    localNavController.tabBarItem.title=@" Display";
    [localViewControllersArray addObject:localNavController];

    PhotoBooth *photo=[[PhotoBooth alloc]initWithNibName:@"Booth" bundle:nil];
    localNavController = [[UINavigationController alloc] initWithRootViewController:photo];
    //localNavController.tabBarItem.image = [UIImage imageNamed:@"Booth.png"];
    localNavController.tabBarItem.title=@"Booth";
    [localViewControllersArray addObject:localNavController];

    More *more=[[More alloc]initWithNibName:@"More" bundle:nil];
    localNavController = [[UINavigationController alloc] initWithRootViewController:more];
    //localNavController.tabBarItem.image = [UIImage imageNamed:@"home.png"];
    localNavController.tabBarItem.title=@"More";
    [localViewControllersArray addObject:localNavController];

    tabBarController.viewControllers = localViewControllersArray;
    [[UITabBarItem appearance] setTitleTextAttributes:
    [NSDictionary dictionaryWithObjectsAndKeys:
    [UIColor grayColor], UITextAttributeTextColor, 
    [UIColor grayColor], UITextAttributeTextShadowColor, 
    [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, 
    [UIFont fontWithName:@"Helvetica" size:0.0], UITextAttributeFont, nil] 
                                             forState:UIControlStateNormal];
    UITabBarItem *tabBarItem1 = [[self.tabBarController.tabBar items] objectAtIndex:0];
    [tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"CentralA.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"Central.png"]];
    UITabBarItem *tabBarItem2 = [[self.tabBarController.tabBar items] objectAtIndex:1];
    [tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:@"DisplayA.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"Display.png"]];
    UITabBarItem *tabBarItem3 = [[self.tabBarController.tabBar items] objectAtIndex:2];
    [tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:@"BoothA.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"Booth.png"]];
    UITabBarItem *tabBarItem4 = [[self.tabBarController.tabBar items] objectAtIndex:3];
    [tabBarItem4 setFinishedSelectedImage:[UIImage imageNamed:@"moreA.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"more.png"]];














2. if u want only change tabbar color then change tabbar tin color
self.tabBarController.tabBar.tintColor = [UIColor colorWithRed:(157/255.0) green:(33/255.0) blue:(33/255.0) alpha:1];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文