I am trying to show NSImage depending on the enum value from Core Data. I am using Value Transformer on an NSImageCell tied to a value on which I select an image to display.
It works great and was supposed to fail when using NSValueTransformer, the image gets an opacity that it shouldn't have.
This is an excerpt from my subclass of NSValueTransformer:
+ (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 relevant static NSImage definitions are:
static NSImage* downloadingImage; static NSImage* downloadFailedImage; static NSImage* downloadCompleteImage;
and the listing I use:
typedef enum { DownloadStatusNone, DownloadStatusDownloading, DownloadStatusComplete, DownloadStatusFailed } DownloadStatus;
Below is a screenshot from a real application and one without NSValueTransformer, but a static NSImage assigned in IB. So this is not a PNG that has alpha or something like that. This happens with three different images from different places.
actual application http://imageshack.us/a/img195/2492/appqe.png static image http://imageshack.us/a/img27/3289/43084671.png
source share