简体   繁体   English

标签栏项目的图像未显示

[英]Image is not showing up for tab bar item

I uploaded an image to assets folder and assigned the image to 1x, 2x and 3x.我将图像上传到资产文件夹并将图像分配给 1x、2x 和 3x。 selected the table view controller of the respective tab bar item -> selected the Attributes -> assigned the image to the image field in the Bar Items section.选择相应标签栏项目的表格视图 controller -> 选择属性 -> 将图像分配给 Bar Items 部分中的图像字段。

After running the application a Blue Square box is showing up on selection and Grayed out square box is showing up on selection of a different bar item.运行应用程序后,选择时会显示一个蓝色方形框,选择不同的栏项时会显示灰色方形框。

Where am I going wrong?我哪里错了?

Go to Assets folder.转到资产文件夹。 Select your tab image.选择您的标签图像。 On the right side under Attributes you will find "Render As".在右侧的“属性”下,您将找到“渲染为”。 Select "Original Image".选择“原始图像”。

When you click on a tab bar icon in one of your view controllers, on the right hand side is where you set the image.当您单击其中一个视图控制器中的选项卡栏图标时,右侧是您设置图像的位置。 What's misleading is that there are two places to set the image in the right sidebar.误导的是右侧边栏中有两个地方可以设置图像。 Under Tab Bar Item > System Item (custom) below that selecting the custom image.Tab Bar Item > System Item (custom)下面选择自定义图像。 Then right below that whole first set there is Bar Item > Image .然后在整个第一组的正下方是Bar Item > Image Mine wouldn't show up until I set the Bar Item > Image as well.在我设置Bar Item > Image之前,我的不会出现。

If you follow BB 's answer, the image will always render in original form in all the places.如果您遵循BB的回答,则图像将始终在所有位置以原始形式呈现。

for my tabbar implementation i had to do the following对于我的标签栏实现,我必须执行以下操作

tabBarItem.selectedImage = UIImage(named: "home").withRenderingMode(.alwaysOriginal);
tabBarItem.image =  = UIImage(named: "home");

So here the image will be rendering as original when the tab is SELECTED (ie, tint will not be applied) and tint will be applied to the tab bar item image when that tab is not selected因此,这里的图像将在选择选项卡时呈现为原始图像(即不会应用色调),并且当未选择该选项卡时,色调将应用于选项卡栏项目图像

@kishor0011: This should fix your problem. @kishor0011:这应该可以解决您的问题。

add tab bar item under view controller, if you embed in view controller in navigation controller tab bar item must be come under Navigation controller.在视图控制器下添加标签栏项目,如果您在导航控制器标签栏项目中嵌入视图控制器,则必须在导航控制器下。

  • View controller when icon not shown未显示图标时查看控制器

未显示图标时查看控制器

Just choose an image in the Bar item section.只需在栏项目部分选择一个图像。 About the selectedImage, check this selectedImage Apple developer documentation关于 selectedImage,查看这个selectedImage 苹果开发者文档

由于我的UIBarButtonItem上的色调,我UIBarButtonItem了这个问题,这解决了问题!

BarButtonItem.image = UIImage(named: "yourImage")?.withRenderingMode(.alwaysOriginal)

转换图像渲染的屏幕截图

First drop your image in the Assets or Images section then click on the image and show to option for Render As in the right side menu.首先将您的图像放入“资产”或“图像”部分,然后单击图像并显示到右侧菜单中的“渲染为”选项。 So change the option from default to Original Image same as shown in above screenshot.因此,将选项从默认更改为原始图像,如上面的屏幕截图所示。

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

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