防止UITabBar对其图标图像应用渐变 [英] Preventing a UITabBar from applying a gradient to its icon images

查看:85
本文介绍了防止UITabBar对其图标图像应用渐变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我为UITabBar制作图标时,它会对图像应用渐变。我需要知道如何防止它出现这种渐变。

When I make icons for a UITabBar, it applies a gradient to the images. I need to know how to prevent it from having this gradient.

推荐答案

Apple在iOS 5中添加了标签栏自定义,现在这个有点东西是微不足道的。在此之前它是一个巨大的黑客,不推荐。

Apple added tab bar customization in iOS 5, and now this kind of stuff is trivial. Prior to this it was a huge hack, and not recommended.

这是如何做一个完全自定义标签栏:

Here's how to do a completely custom tab bar:

// custom icons
UITabBarItem *item = [[UITabBarItem alloc] init];
item.title = @"foo";
// setting custom images prevents the OS from applying a tint color
[item setFinishedSelectedImage:[UIImage imageNamed:@"tab1_active.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab1_image_deselected.png"]];
tab1ViewController.tabBarItem = item;

    // tab bar

    // set background image - will be used instead of glossy black
    tabBarController.tabBar.backgroundImage = [UIImage imageNamed:@"tab_bar_bg.png"];
    // optionally set the tint color - setting this ti nil will result in the standard, blue tint color. tint color is ignored when custom icons are set as above.
    tabBarController.tabBar.selectedImageTintColor = nil;
    // remove the highlight around the selected tab - or provide an alternate highlight image. If you don't do this the iOS default is to draw a highlighted box beneath the selected tab icon.
    tabBarController.tabBar.selectionIndicatorImage = [[UIImage alloc] init];

这篇关于防止UITabBar对其图标图像应用渐变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆