Question

I am trying to show an NSImage depending on a enum value from out of Core Data. I am using a Value Transformer on an NSImageCell bound to the value on which I choose the image to show.

It works perfectly and as intented, unfortunetaly when using the NSValueTransformer the image gets an opacity it is not supposed to have.

This is an excerpt from my NSValueTransformer subclass:

+ (void)initialize
{
    downloadingImage = [NSImage imageNamed:@"downloading.png"];
    downloadFailedImage = [NSImage imageNamed:@"download_failed.png"];
    downloadCompleteImage = [NSImage imageNamed:@"download_complete.png"];
}
+ (Class)transformedValueClass { return [NSImage class]; }
+ (BOOL)allowsReverseTransformation { return NO; }
- (id)transformedValue:(id)value {
    switch([value intValue])
    {
        case DownloadStatusComplete:
            return downloadCompleteImage;
        case DownloadStatusFailed:
            return downloadFailedImage;
        case DownloadStatusNone:
            return nil;
        case DownloadStatusDownloading:
            return downloadingImage;
        default:
            return nil;
    }
}

The corresponding static NSImage definitions:

static NSImage* downloadingImage;
static NSImage* downloadFailedImage;
static NSImage* downloadCompleteImage;

and the enum I use:

typedef enum {
    DownloadStatusNone,
    DownloadStatusDownloading,
    DownloadStatusComplete,
    DownloadStatusFailed
} DownloadStatus;

Below is a screenshot from the actual application and one without the NSValueTransformer but a static NSImage assigned in IB. So it's not the PNG that is having an alpha or something. This happens with three different images from distinct locations.

actual application http://imageshack.us/a/img195/2492/appqe.png static image http://imageshack.us/a/img27/3289/43084671.png

Was it helpful?

Solution

A member of cocoaheads Aachen pointed me to: Why are my images in my NSTableView faded out?

From Jim Correia on Cocoa-Dev:

"On 10.6, NSImageView will draw its content as dimmed when the control is disabled.

Your binding has “Conditionally Sets Enabled” turned on."

This solved it for me!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top