Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 如何使用NSImage在Xcode游乐场中显示图像_Swift_Xcode - Fatal编程技术网

Swift 如何使用NSImage在Xcode游乐场中显示图像

Swift 如何使用NSImage在Xcode游乐场中显示图像,swift,xcode,Swift,Xcode,当我点击侧栏中的眼睛时,我实际上可以预览我的图像。但是,代码的最后一行没有显示任何内容 //: A Cocoa based Playground to present user interface import AppKit import PlaygroundSupport let nibFile = NSNib.Name("MyView") var topLevelObjects : NSArray? let imgView = NSImageView(frame:NSRect(x:

当我点击侧栏中的眼睛时,我实际上可以预览我的图像。但是,代码的最后一行没有显示任何内容


//: A Cocoa based Playground to present user interface

import AppKit
import PlaygroundSupport

let nibFile = NSNib.Name("MyView")
var topLevelObjects : NSArray?

let imgView = NSImageView(frame:NSRect(x: 0, y:0 , width: 300, height: 400))
imgView.image = NSImage(byReferencingFile: "/Users/me/Code/MyPlayground.playground/Resources/image.png")

PlaygroundPage.current.liveView = imgView
  • 打开左侧的项目导航器
  • 选择资源文件夹
  • 右键单击“将文件添加到“资源”
  • 您可以这样使用->imgView.image=UIImage(名为:“image\u name”)