如何在Cocoa中使用CGContext

 

你可以在Cocoa View中使用Core Graphics函数,只需要传递当前图形端口:
 
#define cgrect(nsrect) (*(CGRect *)&(nsrect))
- (void) drawRect: (NSRect) rect
{
    NSRect bounds = [self bounds];
        
    NSGraphicsContext *cocoaContext = [NSGraphicsContext currentContext];
    CGContextRef context = (CGContextRef)[cocoaContext graphicsPort];
        
    CGContextSetLineWidth (context, 5.0);
        
    CGContextBeginPath(context); {
        CGContextAddRect (context, cgrect(bounds));
        CGContextSetRGBFillColor (context, 1.00.90.81.0);
    } CGContextFillPath(context);
        
// drawRec
posted @ 2014-04-14 09:22  dzldzl  阅读(209)  评论(0编辑  收藏  举报