简体   繁体   English

如何在Xcode 11 Playground中使用图像?

[英]How can I use image inside Xcode 11 playground?

I am doing the SwiftUI tutorial which is on the Apple's website in Xcode 11 playground because I use Mojave and not Catalina. 我正在执行SwiftUI教程,该教程位于Apple网站的Xcode 11操场上,因为我使用Mojave而不是Catalina。 There is an image called turtlerock.jpg, but it doesn't show in the playground. 有一个名为turtlerock.jpg的图像,但未在操场上显示。

I put the image inside the resource folder, but no luck. 我将图像放在资源文件夹中,但是没有运气。

I've been scratching my head over this problem too. 我也一直在为这个问题挠头。 I've managed to find at least a workaround for now: 目前,我至少设法找到一种解决方法:

Instead of: 代替:

Image("turtlerock")

try: 尝试:

Image(uiImage: UIImage(named: "turtlerock.jpg")!)

You'll have to have turtlerock.jpg in the Resources folder of your playground. 您必须在游乐场的Resources文件夹中拥有turtlerock.jpg。 If you turn it into a .png first, you can use UIImage(named: "turtlerock") in the above. 如果首先将其转换为.png,则可以在上面使用UIImage(named: "turtlerock")

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

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