0
votes

Because, I need some advanced menubar item, I'm using custom NSView subclass as a view for menubaritem.

In drawrect I'm drawing some simple nsimage, and It works fine with normal displays, but on retina displays, it loads smaller image (yes, I have @2x artwork).

Code:

 - (void)drawRect:(NSRect)dirtyRect
{

    [self.statusItem drawStatusBarBackgroundInRect:dirtyRect withHighlight:self.isHighlighted];
    [icon scalesWhenResized];
    icon = self.isHighlighted ? self.alternateImage : [images objectAtIndex:index];
    NSSize iconSize = [icon size];

    NSRect bounds = self.bounds;
    CGFloat iconX = roundf((NSWidth(bounds) - iconSize.width) / 2);
    CGFloat iconY = roundf((NSHeight(bounds) - iconSize.height) / 2);
    NSPoint iconPoint = NSMakePoint(iconX, iconY);
    [icon drawAtPoint:iconPoint fromRect:bounds operation:NSCompositeSourceOver fraction:1];
}

I tested it with Quartz Debug and on real Retina Macbooks, everything is fine except this little image in menubar.

Update:

self.images = [NSArray arrayWithObjects:[NSImage imageNamed:@"1.png"],[NSImage imageNamed:@"2.png"],[NSImage imageNamed:@"3.png"],[NSImage imageNamed:@"4.png"],[NSImage imageNamed:@"5.png"],[NSImage imageNamed:@"6.png"],[NSImage imageNamed:@"7.png"],[NSImage imageNamed:@"8.png"],[NSImage imageNamed:@"9.png"],[NSImage imageNamed:@"10.png"],[NSImage imageNamed:@"11.png"],[NSImage imageNamed:@"12.png"],[NSImage imageNamed:@"13.png"],[NSImage imageNamed:@"14.png"],[NSImage imageNamed:@"15.png"],[NSImage imageNamed:@"16.png"],[NSImage imageNamed:@"17.png"],[NSImage imageNamed:@"18.png"],[NSImage imageNamed:@"19.png"],[NSImage imageNamed:@"20.png"],[NSImage imageNamed:@"21.png"],[NSImage imageNamed:@"22.png"],[NSImage imageNamed:@"23.png"],[NSImage imageNamed:@"24.png"],[NSImage imageNamed:@"25.png"],[NSImage imageNamed:@"26.png"],
                   nil];
1
Nsarray of nsimage objects, created width imagaNaned method - dormitkon

1 Answers

3
votes

This might be a shot in the dark but if you're loading the images with the extension try dropping it.

Instead of: [NSImage imageNamed:@"icon.png"] do [NSImage imageNamed:@"icon"]

Xcode sets "Combine High Resolution Artwork" to YES which makes your images combined into a TIFF file. So the PNG files don't exist in the bundle thus are not loaded.