【发布时间】:2019-08-20 05:44:17
【问题描述】:
当我想将我的光盘 (/Users/me/Desktop/image.png) 中的图像设置为带有 NSImage(byReferencingFile: ) 的 NSImageView 的图像时,它不会显示。
当我尝试 NSImage(named: ) 使用存储在 assets-folder 中的图像时,它可以工作。
viewController 中的代码
class ViewController: NSViewController {
@IBOutlet var imageView: NSImageView!
override func viewDidLoad() {
super.viewDidLoad()
imageView.image = NSImage(byReferencingFile: "/Users/me/Desktop/image.png")
}
}
imageView 填满了整个窗口。
所以我想加载存储在磁盘上或指定 URL 上的图像。
【问题讨论】:
-
对 URL 使用
convenience init(byReferencing url: URL)。您是否尝试关闭 App Sandbox? -
谢谢,关闭应用沙箱对我有用!
标签: swift xcode macos nsimage nsimageview