Nick Goldman Nick Goldman - 1 year ago 206
Swift Question

Programmatically creating a NSImageView in Swift 3.0

According to the documentation here:

I have tried programmatically creating a NSImage view:

var thing = NSImageView.init(frame:CGRectMake(10, 10, 256, 256))

thing.image = NSImage(named:"test.png")

It runs without any errors in Xcode and successfully creates the view, but nothing can be seen in the view controller anywhere.

I also want to add the following parameters to the view but Xcode cannot find them:



Answer Source

Because you haven't added it to the window yet.

If you use storyboard:


If you use the traditional XIB:


Also, you got the names of the two properties wrong. They should be:

thing.isEditable = true
thing.animates = true
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download