Nathanael Carper
Nathanael Carper

Reputation: 312

Display an Image in an Imageview in OS X Swift

I have a image view box and I want to display an image in it. I know how to do it without writing a line of code but I want to put an image in an image view with code. I've seen many examples online on how to do it in iOS, but I need to know how to do it in OS X. Any help would be appreciated.

Upvotes: 2

Views: 3970

Answers (1)

HardikDG
HardikDG

Reputation: 6112

Create NSImageView object

NSImageView has property 'image'.you can just assign to it.

Ex:

   let imgView = NSImageView(frame:NSRect(x: 0, y: 0, width: 300, height: 300))
   imgView.image = NSImage(named:"test")
   self.view.addSubview(imgView)

Upvotes: 3

Related Questions