Set background color of NSImageView with proportionally sized image

569 views Asked by At

I have subclassed an NSImageView which carries an image set to NSImageScaleProportionallyDown so it will not always occupy the whole space of the view - this is working as it should. Now I don't know how to change the background color respectively the color of tha space that remains unused besides the image... it is by default gray.

I've tried overriding drawRect:

- (void)drawRect:(NSRect)dirtyRect
{
    [[NSColor blackColor] setFill];
    NSRectFill(dirtyRect);
    [super drawRect:dirtyRect];
}

If I leave away the call to super it makes the whole ImageView go black, instead of only the background. If it stays there, there is no change at all - background stays gray...

Anyone has a hint on this, it'd be greatly appreciated.

EDIT: I have the ImageView's styleMask set to NSImageFramePhoto - I need that, because it lets the image be resized the way it needs to be. If I leave it away, the background color works, but with it, it doesn't.

0

There are 0 answers