user688262
user688262

Reputation: 211

Set NSImage.image at runtime with a systemimage under MacOS

In the Interfacebuilder, NSImagebutton offers a wide range of system images to pick (see screenshot). I fail to change these images at runtime under MacOS. Under iOS there is UIImage with UIImage(systemName: "imageName") but MacOS seems to offer nothing comparable?

system images to chose from

Upvotes: 0

Views: 635

Answers (2)

Will Buffington
Will Buffington

Reputation: 1670

As of XCode 15.4: If you are looking to set the image to one of XCode's own image icons you can use the following... this snippet sets an NSButton image to the system image named "magicmouse":

myButton.image = NSImage(systemSymbolName: "magicmouse", accessibilityDescription: nil)

For a list of system images and their names you can view the storyboard, select your button and in the Attributes Inspector click the drop-down next to the "Image" field. What you should see listed are pre-defined System images and their names.

Upvotes: 0

vadian
vadian

Reputation: 285074

It's quite similar in macOS for example

button.image = NSImage(named: NSImage.touchBarQuickLookTemplateName)

Upvotes: 1

Related Questions