Nava Carmon
Nava Carmon

Reputation: 4533

NSColor colorwithpatternimage paints NSView in black color

I'm creating a NSColor using colorWithPatternImage as it shown in Apple example:

- (id)initWithFrame:(NSRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code here.
        backgrColor = [[NSColor colorWithPatternImage:[NSImage imageNamed:@"greenfelt"]] retain];
    }
    return self;
}

- (void)drawRect:(NSRect)dirtyRect {
    [backgrColor set];
    NSRectFill(dirtyRect);
}

The image is taken from the same example and it works there. When I try it in my application, the view is colored in black. Why can it be?

Thanks

Upvotes: 0

Views: 1518

Answers (1)

Cory Kilger
Cory Kilger

Reputation: 13044

It's probably not finding the image, most likely because you're not using an extension on the filename.

Update: A quick test confirms that omitting the extension should still work. But it still may not be finding the image. Maybe it wasn't added to the project or you mistyped the name? Also, I assume that this view is actually being created using -initWithFrame:, right?

Upvotes: 1

Related Questions