2012-01-01 14 views
3

私はnavigationControllerにプッシュされたtabbarcontrollerを持っています。それは動作しません。しかし、私はタブバーの背景色を変更しようとしました: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]; 

これは私がBGの色を変更する同様のポストで見たコードです:

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

insertSubviewの代わりにaddSubviewを試してください – craig1231

答えて

4

を以下のコードは、あなたがウルタブバーにRGB値でカスタム色を追加することができます。

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

これは、背景色、タブバーアイコンの色のみを変更しません –