简体   繁体   English

将图像添加到选项卡栏项目仅显示为块

[英]Adding an image to a tab bar item only shows up as a block

I have a tab bar which should have an image for the selected index. 我有一个选项卡栏,其中应该包含所选索引的图像。

Below is a sample-image which sould be used inside my tab bar. 下面是一个示例图像,可以在我的标签栏中使用。

我要添加的标签栏图像

I have added it by selecting the connected view controller assigned to the tab bar item and replacing the image. 通过选择分配给选项卡栏项目的已连接视图控制器并替换图像来添加它。 However this is what actually appears on the screen. 但这实际上是屏幕上显示的内容。 The assigned graphics is not appearing on the tab bar. 分配的图形未显示在选项卡栏上。

中间的图标

  1. Go to Assets.xcassets 转到Assets.xcassets
  2. Select your image 选择你的图片
  3. Show the Attributes Inspector 显示Attributes Inspector
  4. Change Render As value form Default to Original Image 将“ Render As值形式Default更改为“ Original Image

在此处输入图片说明

You can add this line self.tabBarItem.image = UIImage(named: "icono-menu")?.withRenderingMode(.alwaysOriginal) in your item viewController viewDidLoad 您可以在项目viewController viewDidLoad中添加以下这一行self.tabBarItem.image = UIImage(named: "icono-menu")?.withRenderingMode(.alwaysOriginal)

something like this 像这样的东西

override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.tabBarItem.image = UIImage(named: "icono-menu")?.withRenderingMode(.alwaysOriginal)
    }

set your tabBarImage in assets folder, And set Render as original Image 在资源文件夹中设置tabBarImage,并将“渲染”设置为原始图像 在此处输入图片说明

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

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