2010-12-07 20 views
0

我在我的應用程序中使用帶有多於5個選項卡項目的標籤欄控制器,顏色爲綠色(即自定義)。正如我們所知道的,第6,tabbar項由MoreViewController自動處理。 我的問題是 1)如果我選擇更多Tabbar項目,我得到的藍色項目。 2)如果我從更多Tabbar項目切換到之前的項目,我也確實將項目顏色設置爲藍色。 那麼,如何在兩種情況下將tabbar項目的顏色設置爲綠色?如果我們有5個以上的標籤欄項目,如何設置標籤欄項目的顏色而不是默認的藍色?

回答

0

在蘋果文檔中沒有解決方案。我用我自己的僞造的tabbar結束了自定義按鈕。

0
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"]; 
    [email protected]"Central"; 
    [localViewControllersArray addObject:localNavController]; 
    PuckDisplay *puck=[[PuckDisplay alloc]initWithNibName:@"Display" bundle:nil]; 
    localNavController = [[UINavigationController alloc] initWithRootViewController:uck]; 
    //localNavController.tabBarItem.image = [UIImage imageNamed:@"Display.png"]; 
    [email protected]" Display"; 
    [localViewControllersArray addObject:localNavController]; 

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

    More *more=[[More alloc]initWithNibName:@"More" bundle:nil]; 
    localNavController = [[UINavigationController alloc] initWithRootViewController:more]; 
    //localNavController.tabBarItem.image = [UIImage imageNamed:@"home.png"]; 
    [email protected]"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];