<分区>
我想从 URL 下载图像并在我的 OSX 快速应用程序中显示它。适用于 iOS 的解决方案不适用于 OSX。
我希望下载图像并将其显示在 NSImageView 中。
<分区>
我想从 URL 下载图像并在我的 OSX 快速应用程序中显示它。适用于 iOS 的解决方案不适用于 OSX。
我希望下载图像并将其显示在 NSImageView 中。
最佳答案
简单来说:
let image = NSImage(byReferencingURL:NSURL(string: "http://theinterweb.net/ico/robotics_notes.gif")!)
let imageView = NSImageView()
imageView.image = image
您可以获得Playground Example here ,或者在 Objective-C 中:
NSImage *image = [[NSImage alloc] initByReferencingURL:[NSURL URLWithString:@"http://theinterweb.net/ico/robotics_notes.gif"]];
NSImageView *imageView = [[NSImageView alloc] init];
imageView.image = image;
当然,您可以将 URL 加载到 NSData,然后根据需要转换为 NSImage,就像在 iOS 上一样。
关于swift - Mac Swift - 如何下载图像并将其加载到 NSImageView 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38165291/