我试图弄清楚我在这里做错了什么。尝试了几次,但我从未在屏幕上看到那个难以捉摸的矩形。现在,我只想在屏幕上绘制一个矩形。
除了CGContextSetRGBFillColor()之外,我在所有地方都收到“无效上下文”的错误提示。在此之后获取上下文似乎对我来说是错误的,但我不在家里看我昨晚使用的示例。
我还搞砸了其他东西吗?我真的很想今晚至少完成这么多...
- (id)initWithCoder:(NSCoder *)coder
{
CGRect myRect;
CGPoint myPoint;
CGSize mySize;
CGContextRef context;
if((self = [super initWithCoder:coder])) {
NSLog(@"1");
currentColor = [UIColor redColor];
myPoint.x = (CGFloat)100;
myPoint.y = (CGFloat)100;
mySize.width = (CGFloat)50;
mySize.height = (CGFloat)50;
NSLog(@"2");
// UIGraphicsPushContext (context);
NSLog(@"3");
CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0);
context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, currentColor.CGColor);
CGContextAddRect(context, myRect);
CGContextFillRect(context, myRect);
}
return self;
}
感谢您,Sean。