Add image or icon set to asset catalog to be used with NSToolbarItem

267 Views Asked by At

I have a set of pixel perfect icons which I want to use on toolbar (NSToolbar) of my app. Toolbar is configurable thus I need to provide icons in four sizes: small, standard, small@2x, standard@2x. I could not find any official information about the size of those icons, but unofficial information (confirmed by my tests) is the following: small is 24px, normal is 32px.

Thus I need to add four different images: 24x24px, 32x32px, 48x48px, 64x64px to my image set.

As for now I could not find a correct way for that. I have tried a dozen of different methods but could not find one which preserves pixel perfect quality of all four images.

I believe, I can load right size of the image manually each time it has to be changed, but I am wondering if where is a correct way for that.

Does anyone has a good solution for that?

And yes, I clean build folder before each test.

2

There are 2 best solutions below

1
Ron On

See the Apple Developer site Human Interface guidelines for formats and sizes. The requirements are different for the different devices, and quite detailed.

For a quick & dirty solution if you're not ready to ship and just want nice looking graphics for testing, I've found that one 512 x 512 pdf, labeled "image@2x" works pretty well. You need to set the

imageScaling = .scaleProportionallyDown

and Cocoa will take care of the rest. But it's definitely not ready for prime-time.

1
Albert Renshaw On

The NSToolbar.sizeModes are enum: small and regular. Small is 24x24 and regular is 32x32; additionally the retina options allow for @2x (48x48 and 64x64) and potentially @3x future-forward.

Apple documentation on these sizes can be found here and here

Make sure to use enum Regular not "Standard", which is undocumented.