在iPhone上使用石英绘制虚线

在iPhone上使用石英绘制虚线,iphone,drawing,quartz-graphics,dotted-line,Iphone,Drawing,Quartz Graphics,Dotted Line,我正在开发一个应用程序,我需要在两点之间画虚线。我试过了 CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound) CGContextSetLineDash(UIGraphicsGetCurrentContext(), 0, lengths, LENGTH_OF_ARRAY) 但我看到的是虚线而不是虚线。我怎样才能得到虚线呢 CGContextRef context = UIGraphicsGetCurrentCon

我正在开发一个应用程序,我需要在两点之间画虚线。我试过了

CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound)
CGContextSetLineDash(UIGraphicsGetCurrentContext(), 0, lengths, LENGTH_OF_ARRAY)
但我看到的是虚线而不是虚线。我怎样才能得到虚线呢

CGContextRef context = UIGraphicsGetCurrentContext();
CGFloat lengths[2];
lengths[0] = 0;
lengths[1] = dotRadius * 2;
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context, dotRadius);
CGContextSetLineDash(context, 0.0f, lengths, 2);

// CGContextAddEllipseInRect(context, self.bounds);

这段代码应该可以正常工作。

请参阅下面关于行属性角色的精彩页面!

根据上面的页面,这里是类似(..)的“点”线的代码


这是一篇老文章,但上面的评论实际上没有帮助。那个链接不包括画点,当然有。关于“绘制路径”有一整节,其中描述了如何使用CGContextSetLineDash绘制“线划线图案”
// 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);