自定义UIView compliation错误消息

Ant*_*ong 1 objective-c ios

这是一个代码片段

#import "MyCustomView.h"


@implementation MyCustomView

-(void) drawRect:(CGRect)rect {
    NSLog(@"Help");
    CGContextRef myContext = [[NSGraphicsContext // 1

                               currentContext]graphicsPort];
Run Code Online (Sandbox Code Playgroud)

....

然后在1,我遇到此错误消息:

NSGraphicsContext undeclared (first use in this function)
Run Code Online (Sandbox Code Playgroud)

你知道是什么造成的吗?我应该包含哪个头文件?

Max*_*ann 7

在iOS上,您必须使用它UIGraphicsGetCurrentContext()来获取当前的CGContext.您的电话在Mac OS上有效.