如何在iOS 5中移除UITabbaritem的渐变/投影效果

3

iOS 5版本引入了UI Appearance,有没有简单的方法去除渐变?

我使用这个来自定义我的选项卡栏,有什么方法可以去除渐变效果吗?

谢谢阅读。

-(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个回答

4

UITabBar可以使用一张图片并利用其alpha通道(不透明度)来构建选中/未选中的图像,也可以使用两张处理过的图像。

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


你只能在 iOS 5 及以上版本中使用它。 - lesyk
@lesyk:正确。我链接了文档,文档也说明了这一点,所以我没有提到它。在iOS之前,我不知道如何实现这一点,因为我没有研究过;也许你可以子类化UITabBar,也许你可以自己构建一个。 - Jesper

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接