xcode 如何在 iOS 5 中移除 UITabbaritem 的渐变/阴影

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8890935/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:01:07  来源:igfitidea点击:

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

iphoneiosxcodeuitabbarcontroller

提问by Desmond

with iOS 5, there is UI Appearance, is it possible to remove the gradient easy way ?

使用 iOS 5,有 UI Appearance,是否可以简单地去除渐变?

i do this to customised my tabbar, what can be done to remove the gradient ?

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

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

}

回答by Jesper

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:. There's no other way to affect the processing it does to the images besides changing the color of the gradient with UITabBar's selectedImageTintColorappearance property.

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