2012-01-01 106 views
3

我有一個tabbarcontroller被推到navigationController上。我試圖改變標籤欄的背景顏色但是它不工作:iOS TabBarController背景顏色

UIViewController *viewController1, *viewController2; 
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
     viewController1 = [[Tab1_iPhone alloc] initWithNibName:@"tab1_iPhone" bundle:nil]; 
     viewController2 = [[Tab2_iPhone alloc] initWithNibName:@"tab2_iPhone" bundle:nil]; 
    } 
    self.tabBarController = [[UITabBarController alloc] init]; 

    CGRect frame = CGRectMake(0.0, 0.0, 480, 48); 
    UIView *v = [[UIView alloc] initWithFrame:frame]; 
    [v setBackgroundColor:[UIColor blueColor]]; //003366 
    [v setAlpha:1.0]; 
    [[self.tabBarController tabBar] insertSubview:v atIndex:0]; 


    self.tabBarController.viewControllers = [NSArray arrayWithObjects: viewController1, viewController2, nil]; 
    [self.navigationController setNavigationBarHidden:YES]; 
    [self.navigationController pushViewController:self.tabBarController animated:YES]; 

    [self.window makeKeyAndVisible]; 

這是我上一個類似的職位,改變背景顏色看到代碼:

CGRect frame = CGRectMake(0.0, 0.0, 480, 48); 
    UIView *v = [[UIView alloc] initWithFrame:frame]; 
    [v setBackgroundColor:[UIColor blueColor]]; //003366 
    [v setAlpha:1.0]; 
    [[self.tabBarController tabBar] insertSubview:v atIndex:0]; 

我做有問題?

感謝

+1

嘗試addSubview,而不是insertSubview – craig1231 2012-01-01 23:11:51

回答

4

下面的代碼可以幫助您與RGB值添加自定義顏色,UR的TabBar。

self.tabBarController.tabBar.tintColor = [[UIColor alloc] initWithRed:0.00 
                  green:0.62 
                  blue:0.93 
                  alpha:1.0]; 
+0

這不會更改背景顏色,只有選項卡欄圖標的顏色 – 2017-05-25 14:49:16