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];