iOS TabBarController背景颜色

时间:2012-01-01 23:06:19

标签: ios uitabbarcontroller background-color

我有一个tabbarcontroller,它被推送到navigationController。我试图更改标签栏的背景颜色,但它不起作用:

    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 个答案:

答案 0 :(得分:4)

以下代码可帮助您将带RGB值的自定义颜色添加到tabBar。

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