How to load an image into an Xcode 9 playground?

只愿长相守 提交于 2019-12-12 19:30:48

问题


I've spent hours trying to simply gain access to image data in my Swift Playground. I've followed many tutorials that recommend adding a resource folder as a sibling dir in the dir. your playground is in. Or to drag images into the Resources folder in the playground Navigator. Nothing has worked. What do I have to do to load an image view in playground?


回答1:


I solved this problem on my side when I

  1. import PlaygroundSupport
  2. mark Resources Folder and tap + icon
  3. Choose Add files to 'Resources' and choose your image (here: image.png)
  4. Instance your image via UIImage(named: "image.png")

Screenshot Xcode 9 Playground with UIImage



来源:https://stackoverflow.com/questions/45636060/how-to-load-an-image-into-an-xcode-9-playground

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!