我正在开发一款应用程序,需要在几个点之间绘制虚线。我尝试过
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound)
CGContextSetLineDash(UIGraphicsGetCurrentContext(), 0, lengths, LENGTH_OF_ARRAY)
但是我看到的是虚线而不是点线。如何获得点线?
我正在开发一款应用程序,需要在几个点之间绘制虚线。我尝试过
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);
这段代码应该可以正常运行。
// 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);