试图弄清楚我在这里做错了什么。尝试了几件事,但我从未在屏幕上看到那个难以捉摸的矩形。现在,这就是我想做的——只需在屏幕上绘制一个矩形。
除了 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;
}
谢谢,
肖恩。