iPhone开发笔记[1/50]:初学iPhone上用Quartz 2D画图

参考了An iOS 4 iPhone Graphics Drawing Tutorial using Quartz 2D这篇文章,用了30分钟在iPhone上画出了一条直线,核心代码全在drawRect这个方法中:

- (void)drawRect:(CGRect)rect {
CGContextRef context
= UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context,
2.0);
CGFloat componets[]
= {0.0, 0.0, 1.0, 1.0};
CGColorSpaceRef colorspace
= CGColorSpaceCreateDeviceRGB();
CGColorRef color
= CGColorCreate(colorspace, componets);
CGContextSetStrokeColorWithColor(context, color);
CGContextMoveToPoint(context,
0, 0);
CGContextAddLineToPoint(context,
300, 400);
CGContextStrokePath(context);
CGColorSpaceRelease(colorspace);
CGColorRelease(color);

}

原来在iPhone上画图也不算复杂,与Windows中原理差不多。

posted @ 2011-05-27 08:57  申龙斌的程序人生  阅读(2196)  评论(0编辑  收藏  举报