xcode iphone触摸虚线画

前端之家收集整理的这篇文章主要介绍了xcode iphone触摸虚线画前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我每个身体都是法国人,所以请原谅我的英语.我的问题是我想用手指在 iphone上绘制一个像———–这样的虚线图画,不是一条线而是一个平局.我有:

CGContextSetLineCap(UIGraphicsGetCurrentContext(),kCGLineCapRound); //kCGLineCapSquare,kCGLineCapButt,kCGLineCapRound
CGContextSetLineWidth(UIGraphicsGetCurrentContext(),10.0); // for size
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(),0.0,1.0,1.0); //values for R,G,B,and Alpha
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(),lastPoint.x,lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(),currentPoint.x,currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

请点击“点”代码是什么.

解决方法

CGContextSetLineDash

http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CGContext/Reference/reference.html%23//apple_ref/c/func/CGContextSetLineDash

例:

CGFloat dashes[] = { 1,1 };
CGContextSetLineDash( context,dashes,2 );

或者只需在Xcode中打开QuartzDemo示例并查看QuartzLines.m文件(QuartzDashView类).

你应该阅读文档(参见已经提到过的链接).

猜你在找的Xcode相关文章