简体   繁体   English

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

[英]How to remove gradient / drop shadow for UITabbaritem in iOS 5

with iOS 5, there is UI Appearance, is it possible to remove the gradient easy way ? 使用iOS 5,有UI外观,是否可以轻松删除渐变?

i do this to customised my tabbar, what can be done to remove the gradient ? 我这样做是为了自定义我的tabbar,可以做些什么来删除渐变?

thanks for reading 谢谢阅读

-(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];

}

UITabBar can either take an image and use its alpha channel (opacity) to build the selected/unselected images or take two processed images to use as is. UITabBar可以拍摄图像并使用其Alpha通道(不透明度)来构建选定/未选定的图像,或者将两个处理过的图像按原样使用。

You'll have to provide the images yourself to the UITabBarItem with setFinishedSelectedImage:withFinishedUnselectedImage: . 您必须使用setFinishedSelectedImage:withFinishedUnselectedImage:将您自己的图像提供给UITabBarItem setFinishedSelectedImage:withFinishedUnselectedImage: . There's no other way to affect the processing it does to the images besides changing the color of the gradient with UITabBar's selectedImageTintColor appearance property. 除了使用UITabBar的selectedImageTintColor外观属性更改渐变的颜色之外,没有其他方法可以影响它对图像的处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM