开发者

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 col开发者_高级运维orWithPatternImage:[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


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜