2012-08-01 94 views
0

我试图用颜色填充我的NSView,但它没有使用我想要的颜色。它只是黑色。使用变量设置默认的NSView填充颜色

这是我的NSView的一个子类实现:

#import "OCOvalView.h" 

@implementation OCOvalView 

- (id)initWithFrame:(NSRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 
     bgColorValue = [NSColor greenColor];//I WANT IT TO BE FILLED GREEN 
    } 

    return self; 
} 

- (void)drawRect:(NSRect)dirtyRect 
{ 
    [bgColorValue set]; 
    [NSBezierPath fillRect:[self bounds]];//BUT IT ENDS UP BLACK!! 
} 

@end 

如果我改变[bgColorValue set];[[NSColor greenColor] set];它的工作,但我想用一个变量,如上图所示。

如何获取与bgColorData颜色相同的颜色?

回答

1

解决方案:由于我在initWithFrame:frame范围内设置了bgColorValue,所以在这种情况下不会被调用。我现在将变量设置为:

-(void)awakeFromNib{ 
    bgColorValue = [NSColor greenColor]; 
}