如何将图像加载到 Xcode 9 playground? [英] How to load an image into an Xcode 9 playground?

查看:40
本文介绍了如何将图像加载到 Xcode 9 playground?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了几个小时试图简单地访问我的 Swift Playground 中的图像数据.我遵循了许多教程,这些教程建议在目录中添加一个资源文件夹作为同级目录.你的游乐场在里面.或者将图像拖到 Playground Navigator 的 Resources 文件夹中.没有任何效果.我需要做什么才能在操场上加载图像视图?

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?

推荐答案

我在我这边解决了这个问题

I solved this problem on my side when I

  1. 导入 PlaygroundSupport
  2. 标记资源文件夹并点按+图标
  3. 选择将文件添加到资源"并选择您的图片(此处:image.jpg)
  4. 通过 let image = UIImage(named: "image.jpg")
  5. 实例化你的图片
  1. import PlaygroundSupport
  2. mark Resources Folder and tap + icon
  3. Choose Add files to 'Resources' and choose your image (here: image.jpg)
  4. Instance your image via let image = UIImage(named: "image.jpg")

Xcode 12 预览

这篇关于如何将图像加载到 Xcode 9 playground?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆