开发者

Creating a NSView from a CGPath

开发者 https://www.devze.com 2022-12-29 21:49 出处:网络
I have a CGPath and I want to draw it once to a NSView. Seems relatively simple but I haven\'t found a way in AppKit (non ip开发者_如何转开发hone).Inside -drawRect:, You use CGContextAddPath to add it

I have a CGPath and I want to draw it once to a NSView. Seems relatively simple but I haven't found a way in AppKit (non ip开发者_如何转开发hone).


Inside -drawRect:, You use CGContextAddPath to add it to a context, and use CGContext(Draw|Fill|Stroke)Path to draw it. I.e. you subclass NSView, and override

- (void)drawRect:(NSRect)needsDisplayInRect
{
    CGContextRef cgcontext = [[NSGraphicsContext currentContext] graphicsPort];
    CGContextAddPath(cgcontext,path); // assumes you have CGPathRef*path;
    CGContextStrokePath(cgcontext);
}

Then -drawRect: will be called whenever appropriate. You can force the view to update by calling [view displayIfNeeded].

0

精彩评论

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