我正在尝试从我的启动屏幕中获得一个图像来显示为启动屏幕。故事板文件,但图像从不显示。我有标签显示良好,但图像不出现。

这是启动屏幕在启动屏幕中的外观。故事板文件:

然而,当我在模拟器(以及物理设备)上运行应用程序时,显示如下:

如您所见,标签“Test”显示良好,但图像没有显示。我真的不知道为什么会发生这种情况,我尝试的任何方法似乎都不起作用。如果任何人有任何关于如何解决这个问题的想法,这将是非常感激的。


当前回答

实际上,对于一些重量级图像,将它们添加到图像中并不是一个好情况。Xcassets,因为应用程序加载图像。Xcassets轻量级图像在发布前。所以我把启动画面图像放在加载的第一个根,然后问题就消失了:

在项目的根目录中创建一个新的Group 拖放你的图像在黄色组文件夹内 将其重命名为不同的特殊名称 回到xib(或storyboard)文件,并将ImageView定位为步骤3中的特殊名称。 清理和重建,然后你可以看到你的形象。

提示:您可以在图像中创建您的ImageSet。Xcassets但是把它们放在项目的根目录中。

其他回答

在我的例子中,我可以通过取消对Launchscreen故事板中使用的所有图像视图的属性检查器中的“清除图形上下文”来修复它。

为了你的信息,我已经在资产中导入了图像。PNG格式的Xcassets。

在投入了大量的时间后,我得到了解决方案:-

Step 1:- Quit Xcode
Step 2:- Delete the app from device/simulator
Step 3:- Restart your device (if you are using simulator then you have to quit simulator)
Step 4:- Clear all derived data 
Step 5:- Clear Bin
Step 6:- Open Xcode and relaunch the app, it will work 

You have to make sure that the file name of your image has a format like .png or .jpg at the end otherwise it will not work. Also, before adding your image, you have to make sure that the image file is in your "Assets.xcassets" folder within your project. This can be done with a simple drag and drop. Also, make sure when you've added your image to your storyboard that the image name in the top left also matches the real image file name. I would try looking into Constraints too. Hope this helps. Good luck with your App.

我也面临同样的问题。

添加一个新的图像集到XcodeAssets。 将图像添加到映像集中。 添加图像视图,以启动屏幕和设置您的imageset为图像 在Imageview的属性检查器中,取消选中“清除图形上下文” 清理生成文件夹并再次运行。

我的问题。

原因:我在拖拽到Xcode后重命名了图片。 解决方案:在拖拽到Xcode后不要重命名图像。这给理解Xcode带来了问题。在拖动或添加到Xcode之前重命名图像。

希望它能帮助你!