如何将图像加载到Xcode 9游乐场?

时间:2017-08-11 13:09:37

标签: xcode swift-playground

我花了好几个小时试图在我的Swift Playground中访问图像数据。我已经按照许多教程建议在dir中添加资源文件夹作为兄弟目录。你的游乐场在。或者将图像拖到playground Navigator中的Resources文件夹中。没有任何效果。如何在游乐场加载图片视图?

1 个答案:

答案 0 :(得分:7)

当我

时,我解决了这个问题
  1. import PlaygroundSupport
  2. 标记资源文件夹,然后点按 + 图标
  3. 选择将文件添加到'资源' 并选择您的图片(此处: image.png
  4. 通过UIImage(named: "image.png")
  5. 显示您的图片

    Screenshot Xcode 9 Playground with UIImage