CoreGraphics也称为Quartz 2D是UIKit里边画图的.
IOS常见图形绘制:
- 划线
- 画圆,弧,贝塞尔曲线
- 矩形,椭圆,多边形
- 图片
- 文字
常见概念
- context 上下文,在drawRect里边通过UIGraphicsGetCurrentContext()获取
- path 路径
- stroke,fill 描边,填充
绘制
1 划线
CGContextRef contextRef = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(contextRef, 3);
CGContextBeginPath(contextRef);
CGContextMoveToPoint(contextRef, 100, 200);
CGContextAddLineToPoint(contextRef, 150, 300);
CGContextAddLineToPoint(contextRef, 200, 400);
CGContextStrokePath(contextRef);
2 图像
UIImage *image = [UIImage imageNamed:@"f01r"];
[image drawInRect:CGRectMake(100, 100, 140, 100)];
3 文字
UIFont *font = [UIFont systemFontOfSize:16];
NSDictionary *para = @{NSFontAttributeName:font,NSForegroundColorAttributeName:[UIColor redColor]};
[@"Hello Draw Text" drawInRect:CGRectMake(50, 10, 160, 60) withAttributes:para];