简体   繁体   中英

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. 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.

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. Then right below that whole first set there is Bar Item > Image . Mine wouldn't show up until I set the Bar Item > Image as well.

If you follow BB 's answer, the image will always render in original form in all the places.

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.

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

由于我的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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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