如何在iOS 5中删除UITabbaritem的渐变/投影

时间:2012-01-17 07:17:14

标签: iphone ios xcode uitabbarcontroller

使用iOS 5,有UI外观,是否可以轻松删除渐变?

我这样做是为了自定义我的标签栏,可以做些什么来删除渐变?

感谢阅读

-(void)UIAppearances
{
    //set the background of tab bar
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navbar_bgrd.png"]];

    if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9) {
        //iOS 5
        //[self.tabBarController.tabBar insertSubview:imageView atIndex:1];

        [[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar_bgrd.png"]];
        [[UITabBar appearance] setSelectionIndicatorImage:
         [UIImage imageNamed:@"navbaractive.png"]];


        [[UITabBarItem appearance] setTitleTextAttributes:
         [NSDictionary dictionaryWithObjectsAndKeys:
          [UIColor colorWithRed:75.0/255.0 green:75.0/255.0 blue:75.0/255.0 alpha:1.0], UITextAttributeTextColor, 
          [UIColor clearColor], UITextAttributeTextShadowColor, 
          [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, 
          nil] forState:UIControlStateNormal];

        [[UITabBarItem appearance] setTitleTextAttributes:
         [NSDictionary dictionaryWithObjectsAndKeys:
          [UIColor whiteColor], UITextAttributeTextColor, 
          [UIColor clearColor], UITextAttributeTextShadowColor, 
          [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, 
          nil] forState:UIControlStateSelected];   


        //nav bar
        [[UINavigationBar appearance] setTitleTextAttributes: 
         [NSDictionary dictionaryWithObjectsAndKeys:  
          [UIFont fontWithName:@"Rokkitt" size:28.0],
          UITextAttributeFont,
          nil]];
    }
    else {
        //iOS 4.whatever and below
        [self.tabBarController.tabBar insertSubview:imageView atIndex:0];

    }   

    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque animated:NO];

}

1 个答案:

答案 0 :(得分:4)

UITabBar可以拍摄图像并使用其Alpha通道(不透明度)来构建选定/未选定的图像,或者将两个处理过的图像按原样使用。

您必须自己使用setFinishedSelectedImage:withFinishedUnselectedImage:将图像提供给UITabBarItem。除了使用UITabBar的selectedImageTintColor外观属性更改渐变的颜色外,没有其他方法可以影响它对图像的处理。