带有UIImage的Swift游乐场 [英] Swift playgrounds with UIImage

查看:74
本文介绍了带有UIImage的Swift游乐场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Xcode 6,并且正在尝试重新创建在会话401"Xcode 6的新功能"中演示的代码.我已经将图像添加到Images.xcassets(称为Sample),并且在操场文件中,我尝试按演示方式访问该图像.

I am working with Xcode 6, and I'm trying to recreate the code demoed during session 401 "What's new in Xcode 6". I've added an image to Images.xcassets (called Sample) and within the playground file I'm trying to access this image, as demoed.

我的代码如下(如演示):

My code is as follows (like the demo):

var sample = UIImage(named: "Sample")

但是,我无法使其像演示一样工作.我想念什么吗?

However, I can't get it to work like the demo. Am I missing something?

推荐答案

  1. 在Finder中打开.playground文件.
  2. 在其旁边创建一个名为Resources的文件夹.
  3. 将所需的任何图像添加到此文件夹.
  4. 在操场上,按opt-cmd-1打开File Inspector.您应该会在右边看到游乐场.如果尚未选择,请按cmd-1打开项目导航器",然后单击游乐场"文件.

  1. 在资源路径"下,选择相对于游乐场"
  2. 单击下面的文件夹图标,然后选择先前创建的资源"文件夹.

您现在应该拥有一个可以与标准NSImage一起使用的包(名为:"filename_without_extension"):

You should now have a bundle that you can use with the standard NSImage(named:"filename_without_extension"):

注意:因为Xcode经常会覆盖.playground文件夹,所以我建议使用此方法,这样资源文件夹就不会被不断删除和重新创建.

Note: Because Xcode will frequently overwrite the .playground folder, I recommend using this method so the resources folder isn't getting constantly deleted and re-created.

这篇关于带有UIImage的Swift游乐场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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