我正在尝试从我的启动屏幕中获得一个图像来显示为启动屏幕。故事板文件,但图像从不显示。我有标签显示良好,但图像不出现。
这是启动屏幕在启动屏幕中的外观。故事板文件:
然而,当我在模拟器(以及物理设备)上运行应用程序时,显示如下:
如您所见,标签“Test”显示良好,但图像没有显示。我真的不知道为什么会发生这种情况,我尝试的任何方法似乎都不起作用。如果任何人有任何关于如何解决这个问题的想法,这将是非常感激的。
我正在尝试从我的启动屏幕中获得一个图像来显示为启动屏幕。故事板文件,但图像从不显示。我有标签显示良好,但图像不出现。
这是启动屏幕在启动屏幕中的外观。故事板文件:
然而,当我在模拟器(以及物理设备)上运行应用程序时,显示如下:
如您所见,标签“Test”显示良好,但图像没有显示。我真的不知道为什么会发生这种情况,我尝试的任何方法似乎都不起作用。如果任何人有任何关于如何解决这个问题的想法,这将是非常感激的。
当前回答
我陷入了同样的问题,感谢下面的参考,我能够解决这个问题
https://developer.apple.com/forums/thread/19759?answerId=75438022#75438022
虽然没有必要在为imageview选择图像时更改图像名称和删除扩展名,但我只是简单地创建了一个名为resources的文件夹,并将我的图像添加到该文件夹中,因为我认为将图像直接放入根文件夹中并不好
希望这能有所帮助。
调试快乐!
其他回答
I just figured this out. My launch image was not showing up, I get a white screen when launching on a device (iPhone 6, 7+) or testFlight. Fix: Renamed "Landing_screen.png" to just "Landing_screen" removing .png part. The image icon in Xcode changed to white icon and in the launch screen storyboard the image appears as a question mark now. The Launch image now appears and not the white screen. My Setup: I am using Swift 3.1 with Xcode 8.3.1. In LaunchScreen.storyboard I added a simple image view and stretched the image to fit the view controller. I set auto layout constraints Top/Bottom/Leading/Trailing space to superview to 0 - see image below:
这恰好是XCode/iOS中的缓存问题,但有一个简单的修复方法:在Assets中重命名文件。Xcassets,这样缓存就会重新生成。
我尝试了很多东西(这个线程似乎有一百万个想法,其中一半是相互冲突的)。我的问题是,当我重新启动设备和Xcode时,它会导致图像在应用程序的几个会话中显示,然后它会停止(我不知道为什么,但哇,这很烦人)。
过了无数个小时,我发现a。g的答案是正确的。我做错的一件事是我在xcassets中创建了一个新的图像集,但我仍然在使用故事板中的UIImageView中的图像名称,而不是使用图像集的名称。
为了澄清,你要做的是创建一个新的图像集,并将其命名为“Launch-Defaults”,然后将你的图像添加到它。然后,在故事板的UIImageView内部,你使用图像“Launch-Default”(不包括扩展,因为没有,因为这是一个图像集)。
When you do all of that, the image should actually appear correctly inside of your storyboard. Some people say the image will display blank if you don't use the extension (.jpg or .png), but I assume that is because they are not using the name of the image set. Others say you need to use an extension like .png or .jpg, but the key is to create the image set inside of xcassets and then use that image set inside of the storyboard. When done correctly, there should be no funkiness like an image not showing up or the Launch Screen only working some of the time (requiring a reboot).
我尝试清理项目,删除png,删除约束,但对我来说没有用。
我只是做了一个图像的副本和重命名的副本,然后删除旧的图像,并添加了新的图像(相同,与名称更改),我只是给了那个图像,它为我工作。
我也没有使用资产。Xcassets,使用文件夹中的图像。
在我的例子中,我可以通过取消对Launchscreen故事板中使用的所有图像视图的属性检查器中的“清除图形上下文”来修复它。
为了你的信息,我已经在资产中导入了图像。PNG格式的Xcassets。