手机移动程序开发Web前端之路iOS点点滴滴

CoreGraphics简单使用

2017-11-10  本文已影响6人  海的原滋味

CoreGraphics也称为Quartz 2D是UIKit里边画图的.

IOS常见图形绘制:

常见概念

绘制

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];
上一篇 下一篇

猜你喜欢

热点阅读