0

I have a Table subclass of NSView which contains several blocks of the Block subclass of NSView. This is the code for Table's drawRect: method:

- (void)drawRect:(NSRect)dirtyRect
{
    [NSGraphicsContext saveGraphicsState];
    [[[NSColor whiteColor] colorWithAlphaComponent:0.6] set];
    [NSBezierPath fillRect:dirtyRect];
    [NSGraphicsContext restoreGraphicsState];
}

And this the code of Block's drawRect: method:

-(void)drawRect:(NSRect)dirtyRect
{
    [NSGraphicsContext saveGraphicsState];
    [color set];
    [NSBezierPath fillRect:dirtyRect];
    [NSGraphicsContext restoreGraphicsState];
}

where "color" is set to [[NSColor whiteColor] colorWithAlphaComponent:0].

But I don't understand why, when I run the application, evenrything's fine, but each time I click on a Block this gets filled with the classic gray initial background on Mac OS X... can anybody help? I would be very greatful, thanks.

4

1 回答 1

0

将 Block 的 drawRect 调用更改为 " colorWithAlphaComponent" 到 " 1.0",我想你会准备好的。

零的 alpha 意味着透明的不透明度。查看Apple 的“颜色编程主题”文档,您会看到他们多次提到“alpha”。

ps 你可能想改变“Block”的类名,因为它可能会让那些想传统Objective C 块的人感到困惑^ { }。

于 2012-11-03T20:23:07.020 回答