如何访问UITabBarBackgroundView

时间:2015-10-13 12:55:42

标签: ios objective-c xcode

我一直在尝试制作透明的tabBar背景,但是有一些名为UITabBarBackgroundView的东西,它有白色背景。 我怎样才能访问它?

enter image description here

1 个答案:

答案 0 :(得分:1)

我认为没有直接的方法可以做到这一点。你必须在这里创造一种透明的幻觉。一种方法是在标签栏中设置图像。您可以在UITabBarController上添加以下类别并将其命名为

- (void) setBackgroundImage:(UIImage *)image 
{
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)];
    imageView.backgroundColor = [UIColor colorWithPatternImage:image];
    [self.view addSubview:imageView];
    [self.view sendSubviewToBack:imageView];
    [self.view setOpaque:NO];
    [self.view setBackgroundColor:[UIColor clearColor]];
}

另一种方式(仅限图像方式:)):

UIImage *tabBarBackground = [UIImage imageNamed:@"tabBarBackground.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance] setSelectedImageTintColor:[UIColor colorWithRed:127.0/255.0 green:186.0/255.0 blue:235.0/255.0 alpha:1.0]];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tabBarItemSelected.png"]];