无法在标签栏中显示图标iOS Swift

问题描述:

尽管尝试了SO上发布的各种方法,但在初始化标签栏控制器时,我无法让模拟器显示标签栏图标。无法在标签栏中显示图标iOS Swift

对于每个图标,我提供了3种尺寸,即25px×25px,50px×50px(@ 2x)和75px×75px(@ 3x)。

这是我的TabBar是如何表示模拟器向上 enter image description here

以下是在选项卡和图像分别属性

enter image description here enter image description here

这里是在960x75像素X 960x75像素我的图标中的一个(@ 3x)

enter image description here

有人可以指导我哪里出错了吗?

+0

只是出于好奇你是否运行测试版?我的所有图标都停止显示在测试版中,但会显示在我的手机上。 – Diesel

+0

检查您添加的图像的插图并尝试导入一个像50Px的小图像用于尝试和Xcode版本您正在使用并尝试在设备上启动应用程序也许它只是模拟器问题 –

+0

@Diesel正确的我正在运行X代码9测试版,我尝试在我的设备上启动,但图像仍然不显示。 – kurrodu

我终于想通了,这个问题是与xcassets文件夹做。为了解决这个问题,我在Xcode中创建了一个新的xcassets文件夹。

  1. File > New > Resource > Asset Catalog

  2. 如下图所示,我确定我的目标应用程序也被选中。

我拖放从旧xcassets文件夹中的图片到新的,所有的图像进行加载。

enter image description here

尝试修改如下: -

enter image description here

,然后更新您的自定义图像编程

if let tabBarItems = yourTabBar?.items { 
    tabBarItems[0].selectedImage(UIImage(name: yourImage) 
} 

对于雨燕3.0

编程设置为选定的选项卡,然后取消选择的标签图像

let arrayOfImageNameForSelectedState = ["tabBar_img_1", "tabBar_img_2", "tabBar_img_3"] 
    let arrayOfImageNameForUnselectedState = ["tabBar_img_1", "tabBar_img_2", "tabBar_img_3"] 

    if let count = self.tabBar.items?.count { 

     for i in 0...(count-1) { 

      let imageNameForSelectedState = arrayOfImageNameForSelectedState[i] 
      let imageNameForUnselectedState = arrayOfImageNameForUnselectedState[i] 

      self.tabBar.items?[i].selectedImage = UIImage(named: imageNameForSelectedState)?.withRenderingMode(.alwaysOriginal) 
      self.tabBar.items?[i].image = UIImage(named: imageNameForUnselectedState)?.withRenderingMode(.alwaysOriginal) 
     } 
    }