IOS绘图
来源:互联网 发布:淘宝客服业绩软件 编辑:程序博客网 时间:2024/05/16 15:36
- (void)drawRect:(CGRect)rect{ //该方法提供给我们在视图显示之前自己绘制一些东西 //不需要创建画板 //获取当前的画板 CGContextRef context = UIGraphicsGetCurrentContext(); //设置画笔的颜色 // CGContextSetStrokeColorWithColor(context, <#CGColorRef color#>) CGContextSetRGBStrokeColor(context, 1, 0, 0, 1); //设置线条的宽度 CGContextSetLineWidth(context, 10); //线条的样式 CGContextSetLineCap(context, kCGLineCapButt); //把画笔移到某个点 if (allLinesArr.count == 0) { return; } for (NSMutableArray *smallArr in allLinesArr) { CGPoint firstPoint = [smallArr[0] CGPointValue]; CGContextMoveToPoint(context, firstPoint.x, firstPoint.y); //跟另一个点连成一条线 for (int i = 1; i < smallArr.count; i++) { CGPoint nextPoint = [smallArr[i] CGPointValue]; CGContextAddLineToPoint(context, nextPoint.x, nextPoint.y); } } //把画板上刚才描的路径画出来 //画线 CGContextStrokePath(context); //画圆 //CGContextStrokeEllipseInRect(context, CGRectMake(150, 200, 200, 200)); //画矩形 // CGContextStrokeRect(context, CGRectMake(80, 220, 250, 250));}- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ pointArr = [[NSMutableArray alloc]init]; UITouch *touch = [touches anyObject]; CGPoint beginPoint = [touch locationInView:self]; [pointArr addObject:[NSValue valueWithCGPoint:beginPoint]]; [allLinesArr addObject:pointArr];}- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ UITouch *touch = [touches anyObject]; CGPoint movePoint = [touch locationInView:self]; [pointArr addObject:[NSValue valueWithCGPoint:movePoint]]; [self setNeedsDisplay];}- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ }
0 0
- IOS 绘图
- iOS绘图
- ios绘图
- iOS绘图
- ios 绘图
- iOS 绘图
- ios绘图
- iOS 绘图
- iOS 绘图
- IOS绘图
- iOS 绘图
- iOS绘图
- ios 绘图
- ios绘图
- ios绘图
- iOS绘图
- iOS绘图
- IOS绘图
- 九度OJ 1091:棋盘游戏 (DP、BFS、DFS、剪枝)
- Android: LinearLayout布局和其嵌套运用举例
- github 远程仓库
- 第七周项目5--排队看病模拟
- PHP开发环境思考
- IOS绘图
- 第八周项目2-建立链串的算法库
- 1021. 个位数统计 (15)
- 第7周项目2 - 建立链队算法库
- 第7周 项目1-建立顺序环形队列算法库
- github分支管理
- 第八周-项目1 - 建立顺序串的算法库
- 第6周项目4 数制转换
- 第六周项目3括号的匹配