我有一个非常简单的项目,涉及使用 drawRect 绘制形状,但我不相信我的 drawRect 函数实际上被调用了。这是代码。(其他一切都只是“单一视图应用程序”的默认设置。)
-(void)drawRect:(CGRect)aRect{
NSLog(@"testing...");
CGContextRef context=UIGraphicsGetCurrentContext();
CGContextBeginPath(context);
CGContextMoveToPoint(context, 50, 50);
CGContextAddLineToPoint(context, 100, 120);
CGContextAddLineToPoint(context, 20, 100);
CGContextClosePath(context);
[[UIColor greenColor] setFill];
[[UIColor redColor] setStroke];
CGContextDrawPath(context,kCGPathFillStroke);
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view setNeedsDisplay];
}
任何建议都会很棒——感谢阅读!