2011-10-31 92 views
0

我已在Xcode 4.2和Snow Leopard iPhone應用程序中,我已通過實施下面的代碼的TabBar背景顏色和IOS 5

CGRect frame = CGRectMake(0.0, 0.0, self.view.bounds.size.width, 48); 
UIView *v = [[UIView alloc] initWithFrame:frame]; 
[v setBackgroundColor:[UIColor colorWithRed:1.0f/255.0f green:140.0f/255.0f  
    blue:131.0f/255.0f alpha:1.0f]]; 
    [[self.tabBarController tabBar] insertSubview:v atIndex:0]; 
[v release]; 

    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:1.0f/255.0f  
    green:125.0f/255.0f blue:131.0f/255.0f alpha:1.0f]; 

它是設置在導航欄和標籤欄背景顏色工作正常,但現在如果我在ios 5和xcode 4.2中運行這個應用程序,導航欄顏色設置但tabbar背景顏色不設置

如何在ios 5中設置tabbar的背景顏色?如果有人知道請幫助我。

非常感謝。

+0

http://stackoverflow.com/questions/7779736/how-to-set-image-background-to-uitabbarcontroller- ios-5 –

+0

它工作與否? –

+0

是的,它正在工作......非常感謝... –

回答

2
CGRect frame = CGRectMake(0.0, 0.0, 320, 48);//Setting a Frame. 

    myTabView = [[UIView alloc] initWithFrame:frame];//Making Tab View 

    // not supported on iOS4  
    UITabBar *tabBarr = [self.tabBar tabBar]; 
    if ([tabBarr respondsToSelector:@selector(setBackgroundImage:)]) 
    { 
     // set it just for this instance 
     [tabBarr setBackgroundImage:[UIImage imageNamed:@"hot-1.png"]]; 


     // set for all 
     // [[UITabBar appearance] setBackgroundImage: ... 
    } 
    else 
    { 
     // ios 4 code here 
     //[tabBarr setBackgroundColor:c]; 
    } 

    //[myTabView setBackgroundColor:c];//Setting Color Of TaBar. 

    [myTabView setAlpha:0.8];//Setting Alpha of TabView. 

    [[self.tabBar tabBar] insertSubview:myTabView atIndex:0];//Inserting Tab As SubView. 

使用這個,而不是設置顏色的TabBar的背景....