美文网首页
【iOS】CGContext 绘图

【iOS】CGContext 绘图

作者: 印比八方来 | 来源:发表于2018-10-07 09:28 被阅读0次

在drawRect:(CGRect)rect方法中编写

一.画线/直线图形

UIColor *pathColor = [UIColor performSelector:colorSelector withObject:nil];
CGFloat r, g, b, a;
[pathColor getRed:&r green:&g blue:&b alpha:&a];

// 取得画布
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineCap(context, kCGLineCapSquare); // 设置终点类型
CGContextSetRGBStrokeColor(context, r, g, b, a); // 设置画笔颜色
CGContextBeginPath(context); // 开始绘画
CGContextMoveToPoint(context, leftPoint.x, leftPoint.y); // 设置点位置
CGContextAddLineToPoint(context, upPoint.x, upPoint.y); // 连线

CGContextStrokePath(context); // 绘线

二.画带有填充色的图形

// 在CGContextBeginPath后编写填充颜色代码
CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextDrawPath(context, kCGPathFillStroke);

相关文章

网友评论

      本文标题:【iOS】CGContext 绘图

      本文链接:https://www.haomeiwen.com/subject/abokaftx.html