CoreGraphics简单使用

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];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容