CGContextRef 与CGMutablePathRef画图用法
来源:互联网 发布:会计帐套软件 编辑:程序博客网 时间:2024/06/07 09:44
As all know ,CGContextRef 与 CGMutablePathRef 都是画图工具,其中CGMutablePathRef 可与CAShapeLayer或CGContextRef配合使用.
CGContextRef用法
获取当前图形上下文:
CGContextRef context =UIGraphicsGetCurrentContext();
设置线条颜色:CGContextSetStrokeColorWithColor(context,color1.CGColor);
CGContextSetRGBStrokeColor(context,R,G,B);
设置填充颜色:
CGContextSetFillColorWithColor(context, aColor.CGColor);
绘图起点:
CGContextMoveToPoint(context,x,y);
连接线段:CGContextAddLineToPoint(context,200,20);
画弧度:CGContextAddArc(CGContextRef cg_nullable c, CGFloat x, CGFloat y,
CGFloat radius, CGFloat startAngle, CGFloat endAngle,int clockwise)
线段绘制结束:CGContextStrokePath(context);
弧度绘制结束:CGContextClosePath(context);
CGContextDrawPath(context,kCGPathFillStroke);
CGMutablePathRef用法
CAShapeLayer *shapeLayer = [CAShapeLayerlayer];
[shapeLayer setStrokeColor:[UIColorblackColor].CGColor];
[shapeLayer setLineWidth:1];
[shapeLayer setLineJoin:kCALineJoinRound];
设置虚线的线宽及间距
[shapeLayer setLineDashPattern:[NSArrayarrayWithObjects:[NSNumbernumberWithInt:2], [NSNumbernumberWithInt:3],nil]];
创建虚线绘制路径
CGMutablePathRef path =CGPathCreateMutable();
设置y轴方向的虚线
CGPathMoveToPoint(path,NULL, point.x, point.y);
CGPathAddLineToPoint(path,NULL, point.x,zzHeight-margin);
设置虚线绘制路径
[shapeLayer setPath:path];
CGPathRelease(path);
[self.layeraddSublayer:shapeLayer];
添加弧度路径void CGPathAddQuadCurveToPoint(CGMutablePathRef cg_nullable path,
const CGAffineTransform *__nullable m, CGFloat cpx, CGFloat cpy,
CGFloat x, CGFloat y)
CG_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_2_0);
与CAShapeLayer或CGContextRef配合使用
CGContextAddPath(context,path);
CGContextDrawPath(context,kCGPathStroke);
CGPathRelease(path);
[shapeLayer setPath:path];
CGPathRelease(path);
附:
CGContextSetInterpolationQuality 设置图形上下文的插值质量水平。
CGContextSetLineCap 图形环境中的画线的端点的样式设置。
CGContextSetLineDash 设置图形上下文中的虚线的模式。
CGContextSetLineJoin 设置图像上下文中的接接线的样式。
CGContextSetLineWidth 设置图像上下文中的线的宽度。
CGContextSetMiterLimit 设置图像上下文中的连接线的斜接限制。
CGContextSetPatternPhase 设置一个上下文的段落模式。
CGContextSetFillPattern 在指定的图形上下文设置的填充图案模式。
CGContextSetRenderingIntent 在当前图形状态设置渲染意向。
CGContextSetShouldAntialias 设置图形上下文的抗锯齿开启或关闭。
CGContextSetStrokePattern 在指定的图形上下文设置描边图案。
- CGContextRef 与CGMutablePathRef画图用法
- CGContextRef CGMutablePathRef UIBezierPath
- 关于CGContextRef和CGMutablePathRef&UIBezierPath
- CGContextRef画图
- CGContextRef画图
- IOS CGContextRef画图小结
- iOS CGContextRef画图小结
- iOS CGContextRef画图小结
- iOS CGContextRef画图小结
- iOS CGContextRef画图小结
- iOS CGContextRef画图小结
- 画图CGContextRef相关
- iOS CGContextRef画图小结
- iOS用CGContextRef画图
- 关于CGContextRef画图
- CGContextRef画图小结
- iOS用CGContextRef画图
- CGContextRef画图了解(转载)
- Redis数据库入门
- UGui 之 Canvas 组件
- js 模糊匹配
- 针对IIS6.0 WebDAV漏洞(cve-2017-7269)制作纯字符数字的shellcode回连msf
- Jackson的使用(json解析)
- CGContextRef 与CGMutablePathRef画图用法
- Linux计算机届的Model S即将诞生
- 将osworkflow与spring和hibernate集成的基本介绍
- android可执行文件出现error: only position independent executables (PIE) are supported.
- JAVA8 十大新特性详解
- ios SDAutolayout的使用心得
- Chromium OS?本土化气息的的Flint OS
- Android Universal-Image-Loader
- Android截取某一个view的屏幕