Nikolay Tsenkov
Nikolay Tsenkov

Reputation: 1128

How to select image for NSStatusItem for regular and retina display?

Should I be "detecting" if it's retina display (not sure how would this work with mixed displays) and select the correct image for the NSStatusItem of my app? Please, give an example.

Thanks.

Upvotes: 1

Views: 771

Answers (1)

mahal tertin
mahal tertin

Reputation: 3416

  • No coding required
  • You don't have to check for the display resolution
  • use the @2x Naming Convention for your images and you're all set

Example:

You have "status.png" and "[email protected]", as well as "status_negative.png" and "[email protected]" for the alternate image (on selection). Here is how you load it:

statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
NSImage *statusImage = [NSImage imageNamed:@"status"];
[statusItem setImage:statusImage];
NSImage *altStatusImage = [NSImage imageNamed:@"status_negative"];
[statusItem setAlternateImage:altStatusImage];

[statusItem setHighlightMode:YES];

[statusItem setMenu:statusMenu];

Upvotes: 3

Related Questions