4

HI every body I'm french so scuse me for my english. My problem is that I want to draw with my finger on the iphone a dotted drawing like that -----------, not a line but a draw.I have :

CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); //kCGLineCapSquare, kCGLineCapButt, kCGLineCapRound
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10.0); // for size
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 1.0, 0.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();

What is the code for "dotted" please.

4

3 回答 3

4

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, 0.0, dashes, 2 );

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

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

于 2011-02-19T18:05:14.177 回答
2

您的问题是您在执行此操作之前没有引用上下文: CGContextSetLineDash( context, 0.0, dashes, 2 );

您需要这样做:CGContextRef context = UIGraphicsGetCurrentContext();然后用上下文替换所有 UIGraphicsGetC... 调用,以加快速度。

Deitel 的 iPhone App-Driven Approach 书中有一个这样做的例子。

格斗

于 2011-03-14T05:12:35.463 回答
0

请参阅有关线属性角色的精彩页面! https://horseshoe7.wordpress.com/2014/07/16/core-graphics-line-drawing-explained/

根据上面的页面,这里是“点”行的代码,如(......)

// should
CGContextSetLineCap(context, kCGLineCapRound);

// please see the role of line properties why the first should be 0 and the second should be the doulbe of the given line width
CGFloat dash[] = {0, lineWidth*2};

// the second value (0) means the span between sets of dot patterns defined by dash array
CGContextSetLineDash(context, 0, dash, 2);
于 2016-09-01T02:53:05.613 回答