形を描きたかったのですが、その上に小さな透明な形を描きたかったのです。
-(void) drawRect:(NSRect)dirtyRect
{
//clear everything
{
[[NSColor whiteColor] set];
[[NSBezierPath bezierPathWithRect:dirtyRect] fill];
}
NSBezierPath *thePath = [NSBezierPath bezierPathWithOvalInRect: self.bounds];
[thePath setLineWidth: 30];
[[NSColor blueColor] set];
[thePath stroke];
[[NSGraphicsContext currentContext] setCompositingOperation: NSCompositeCopy];
[[NSColor clearColor] set];
[thePath setLineWidth: 4];
[thePath stroke];
}
私も NSImage forst を使って試してみましたが、それでも同じ結果が得られました。
-(void) drawRect:(NSRect)dirtyRect
{
//clear everything
{
[[NSColor whiteColor] set];
[[NSBezierPath bezierPathWithRect:dirtyRect] fill];
}
NSImage* image = [[NSImage alloc] initWithSize:self.frame.size];
[image lockFocus];
//clear everything
{
[[NSColor whiteColor] set];
[[NSBezierPath bezierPathWithRect:dirtyRect] fill];
}
NSBezierPath *thePath = [NSBezierPath bezierPathWithOvalInRect: self.bounds];
[thePath setLineWidth: 30];
[[NSColor blueColor] set];
[thePath stroke];
[[NSGraphicsContext currentContext] setCompositingOperation: NSCompositeCopy];
[[NSColor clearColor] set];
[thePath setLineWidth: 4];
[thePath stroke];
[image unlockFocus];
[image drawInRect:self.frame fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0];
}