简体   繁体   English

如何正确显示标签栏项目的图标

[英]How to show the tab bar item's icon correctly

I have created an application using storyboard and has a tab bar controller with 3 tabs. 我使用storyboard创建了一个应用程序,并且有一个带有3个选项卡的标签栏控制器。 Each tab has a tab icon and a tab title, and I have two styles images (checked and unchecked) for the tab icons. 每个选项卡都有一个选项卡图标和一个选项卡标题,我有两个样式图标(已选中和未选中)。 Both are 54*54. 两者都是54 * 54。

检查是蓝色的未选中是灰色的

When I select the tab bar item using storyboard, in its attributes inspector, If I set the Bar item's Image to be the checked one , it will show some strange thing like this: 当我使用storyboard选择标签栏项目时,在其属性检查器中,如果我将Bar项目的Image设置为已选中,它将显示一些奇怪的事情:

奇怪

Of course that's not I want. 当然那不是我想要的。 I guess maybe the problem is that my checked icon is blue. 我想问题可能是我的选中图标是蓝色的。

I am wondering how can I get the right icon for the tab. 我想知道如何获得选项卡的正确图标。 Both in right size and appearance. 尺寸和外观都合适。

Also, could someone tell me what's the difference about "Tab Bar Item" and "Bar Item"? 另外,有人可以告诉我“Tab Bar Item”和“Bar Item”的区别是什么?

在此输入图像描述

To resolve the problem with 'strange thing' with the image, you can do this in code: (Sorry, I don't know the proper word for that either) 要解决图像中“奇怪的事情”的问题,你可以在代码中执行此操作:(抱歉,我也不知道正确的单词)

UIImage *image = [[UIImage imageNamed:@"imageName"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

Then assign this image to the UITabItem's image: 然后将此图像分配给UITabItem的图像:

UITabBarItem * tabItem = [tabBarController.tabBar.items objectAtIndex:0];
tabItem.image = image;

I don't exactly know how you can do this in storyboard. 我不知道如何在故事板中做到这一点。

You could also resize your image to the correct size, either outside (using preview) or inside, with code (Search for a method to resize an UIImage). 您还可以在外部(使用预览)或内部使用代码(搜索调整UIImage大小的方法)将图像调整为正确的大小。

  • Size Issue: I recommend you to use Sketch as you App Icon Tool which is capable of importing your icon, custom one or downloaded one, to three size (@1x,@2x and @3x) conveniently. 尺寸问题:我建议您使用Sketch作为App Icon Tool,它可以方便地将您的图标,自定义图标或下载图标导入三种尺寸(@ 1x,@ 2x和@ 3x)。 And I do not recommend you set your icon's size in the code. 我不建议您在代码中设置图标的大小。
  • Highlight Issue: You showed you have different-light types for icon, you can set blue one as the highlight-icon for Selected Image in the panel Tab Bar Item . 突出显示问题:您显示图标有不同的灯光类型,您可以在面板Tab Bar Item中将蓝色图标设置为Selected Image的突出显示图标。
  • Item Bar Issue: I think the Bar Item is part of Tab Bar Item . 项目栏问题:我认为Bar ItemTab Bar Item一部分。 If you just used the Default icon, like More , favorited , feather , then you do not need to set the Tab Bar Item . 如果您刚刚使用Default图标,例如Morefavoritedfeather ,那么您不需要设置Tab Bar Item And you shall choose your own icon in the Tab Bar Item after you selected the System Item as Custom . 选择System ItemCustom后,您将在Tab Bar Item选择自己的icon

I just meet the same question!And then I figure out it! 我只是遇到同样的问题!然后我弄明白了!

There is nothing wrong with your code or setting 您的代码或设置没有任何问题

It's about your IMAGEs 这是关于你的IMAGE

You can just look at the apps on your phone.(almost)Any tab bar item icons are in gray. 您只需查看手机上的应用程序。(差不多)任何标签栏项目图标均为灰色。

So the Icon will just display their UN Hollow parts in gray!! 所以Icon只会将他们的UN空心部件显示为灰色!!

[Additionally,according to official API,they wrote like this: [另外,根据官方API,他们写道如下:

By default, unselected and selected images are automatically created from the alpha values in the source images . 默认情况下,将根据源图像中Alpha值自动创建未选择和选定的图像 To prevent system coloring, provide images with UIImageRenderingModeAlwaysOriginal . 要防止系统着色,请使用UIImageRenderingModeAlwaysOriginal提供图像。

] ]

Consequently the solution is : USE Sketch to make your instance's icon heart-part to be hollow 因此,解决方案是:使用草图使您的实例的图标心脏部分为空心

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

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