显示所选UITabBarItem(故事板)iOS10的原始图像
我使用的UITabBarController带有5个ViewController每个ViewController都有自己的UINavigationController,如下所示: 我添加了tabar图像,如 如上图所示,当选择TabBarItem时,我可以看到蓝色的图像…我想显示所选tabaritem的原始图像 我已经看到了设置属性UIImageRenderingModeAlwaysOriginal的示例。但我在黑板上看不到任何东西 下面是我推TabBarController的方式:显示所选UITabBarItem(故事板)iOS10的原始图像,ios,objective-c,Ios,Objective C,我使用的UITabBarController带有5个ViewController每个ViewController都有自己的UINavigationController,如下所示: 我添加了tabar图像,如 如上图所示,当选择TabBarItem时,我可以看到蓝色的图像…我想显示所选tabaritem的原始图像 我已经看到了设置属性UIImageRenderingModeAlwaysOriginal的示例。但我在黑板上看不到任何东西 下面是我推TabBarController的方式: Hom
HomeViewController *vcHome = (HomeViewController*)[[UIStoryboard storyboardWithName:@"NexTabBar" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"ID_HOME_VC"];
vcHome.delegate = self;
[self.navigationController pushViewController:vcHome animated:YES];
如何在此处使用UIImageRenderingModeAlwaysOriginal属性,以便在选择特定选项卡项时可以看到原始图像
或者如果ios10还有其他方法。以下是我如何为myTabBar创建tabBarItem的方法
let storyboard = UIStoryboard(name: storyboardIdentifier, bundle: nil)
let vc:UIViewController? = storyboard.instantiateInitialViewController();
let selectedImage = UIImage(named: imageName)
let notSelectedImage = UIImage(named:selectedImageName)?.withRenderingMode(.alwaysOriginal)
let item = UITabBarItem(title: title, image: notSelectedImage, selectedImage: selectedImage)
vc!.tabBarItem = item
目标C版本:
UIStoryboard *sb = [UIStoryboard storyboardWithName:storyboardIdentifier bundle:nil];
UIViewController* vc = sb.instantiateInitialViewController;
UIImage* selectedImage = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage* notSelectedimage = [[UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UITabBarItem* item = [[UITabBarItem alloc]initWithTitle:title image:notSelectedimage selectedImage:selectedImage];
[[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];
vc.tabBarItem = item;
return vc;
如果这没有帮助,请尝试更改tabBar的颜色
self.tabBar.barTintColor = .orange
// set color of selected icons and text to white
self.tabBar.tintColor = .white
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.white], for: .selected)
// set color of unselected text to gray
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.gray], for: .normal)
你的第一张图像太模糊了,你能提供一个高分辨率的吗?它只是故事板中的UIAbbarController…有五个TabBarItem…基本的控制器我只能拿出屏幕短片…有UIImageRenderingModeAlwaysOriginal属性,但我不知道如何在我的情况下使用…当我们从故事板加载UIAbbarController时。。。而且不是以编程方式…我尝试过,但它只是将未选择的颜色更改为白色,因为setSelectedImageTintColor不可用我添加了SetUnselectedEditTintColor。选择图像时,仍显示蓝色默认图像…:(