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

发布于 2024-12-27 12:23:29 字数 1941 浏览 0 评论 0原文

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

}

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

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

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苍暮颜 2025-01-03 12:23:29

UITabBar 可以获取图像并使用其 Alpha 通道(不透明度)来构建选定/未选定的图像,也可以获取两个处理后的图像按原样使用。

您必须自己将图像提供给 UITabBarItem setFinishedSelectedImage:withFinishedUnselectedImage:。除了使用 UITabBar 的 selectedImageTintColor 外观属性。

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.

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 selectedImageTintColor appearance property.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文