object-c图形绘制总结
来源:互联网 发布:数字电子网络配线架 编辑:程序博客网 时间:2024/05/16 12:09
图形绘制:直线,贝塞尔曲线,多边形,圆形,扇形
1.绘制图形最开始我们要做的是:
CGContextRef ctx = UIGraphicsGetCurrentContext();//获得当前的上下文CGContextSaveGState(ctx);//保存空白图形到上下文栈2.开始绘制
//拼接路径绘制直线 CGContextMoveToPoint(ctx, 100, 100); CGContextAddLineToPoint(ctx, 200, 200);//绘制三角形 CGContextMoveToPoint(ctx, 10, 100); CGContextAddLineToPoint(ctx, 10, 200); CGContextAddLineToPoint(ctx, 300, 300); //关闭路径 CGContextClosePath(ctx); //圆心,坐标,半径,开始角度,结束角度,角度,方向,关闭路径可以绘制扇形 CGContextAddArc(ctx, 180, 300, 150, 0, M_PI, 1);//绘制四边形 CGContextAddRect(ctx, CGRectMake(80, 200, 200, 200));//绘制曲线 CGContextMoveToPoint(ctx, 10, 100);//绘制起点 CGContextAddQuadCurveToPoint(ctx, 200, 50, 150, 150);//绘制二次曲线 CGContextAddCurveToPoint(ctx, 0, 100, 0, 300, 0, 300);
3.绘制图形的一些简单设置
CGContextSetLineWidth(ctx, 10);//设置宽度 CGContextSetStrokeColorWithColor(ctx, [UIColor cyanColor].CGColor);//设置颜色 CGContextSetLineCap(ctx, kCGLineCapRound);//设置直线两头为圆滑 const CGFloat length[] = {5,10,3,4,5,6,7,7};//实线,空白长度 CGContextSetLineDash(ctx, 0, length, 7);//绘制虚线 CGContextSetLineCap(ctx, kCGLineCapRound);//线头为圆 [[UIColor blueColor] setStroke];//设置画笔颜色 [[UIColor brownColor] setFill];//填充颜色4.绘制
CGContextStrokePath(ctx);//渲染,完成绘制
贝赛尔曲线的绘制(实现折线图):
//创建呗赛尔曲线 UIBezierPath *path = [UIBezierPath bezierPath]; //枚举器这个数组里面存得时坐标CGPoint [array enumerateObjectsUsingBlock:^(NSValue *obj, NSUInteger idx, BOOL * _Nonnull stop) { //获得数组对象转换为CGPoint CGPoint point = [obj CGPointValue]; //添加到呗赛尔曲线 [path addLineToPoint:point]; //创建转折圆点 CGRect rect = CGRectMake(point.x-3, point.y-3, 10, 10);// UIBezierPath *arcPoint = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:5];//这个也可以画圆点 UIBezierPath *arcPoint = [UIBezierPath bezierPathWithOvalInRect:rect]; //拼接路径 [path appendPath:arcPoint]; }]; //创建模型图层 CAShapeLayer *shapeLayer = [CAShapeLayer layer]; //设置frmae shapeLayer.frame = CGRectMake(0, 0, 375, 667); //设置颜色 shapeLayer.fillColor = [UIColor blueColor].CGColor; shapeLayer.strokeColor = [UIColor redColor].CGColor; shapeLayer.path = path.CGPath;//将曲线放进图层 //添加图层 [self.layer addSublayer:shapeLayer];
0 0
- object-c图形绘制总结
- OBJECT ARX 绘制常用图形 总结
- OBJECT ARX三维图形绘制
- 绘制图形总结
- QGraphics绘制图形总结
- android绘制图形总结
- C#—绘制图形
- [Object-C语言随笔之四]创建视图并绘制简单图形
- [Object-C语言随笔之四]创建视图并绘制简单图形
- XCode Object-C 绘制边框
- 数学建模常用Matlab/Lingo/c代码总结系列——Matlab图形绘制函数汇总
- MFC绘图总结-DIB图形绘制
- Quart 2D 绘制图形简单总结
- Quart 2D 绘制图形简单总结
- 图形绘制系统的体系结构总结
- C++Directx11开发笔记三:绘制图形
- object-c 总结
- Object-C编程总结
- android笔记--保存和恢复activity的状态数据
- CString之GetBuffer
- android NDK开发编译时出现Type 'jint' could not be resolved和Unresolved inclusion: <jni.h>的解决办法
- OC_02
- 集合collection的实现类List,set以及map
- object-c图形绘制总结
- 指针学习注意点
- 【转载整理】Android对话框
- Django+Jquery+Bootstrap Modal+Iframe使用异步机制上传文件实现方法
- 《game design workshop》阅读笔记(四)——Game Design Basics——Working with Formal Elements
- MySQL Community Server 5.7 的数据备份
- HelloWorldServlet
- 用例图之包含、扩展、泛化
- mmap函数用法及示例程序