Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw dotted lines using Quartz on iPhone

I am developing an application in which I need to draw dotted lines between a couple of points. I tried

CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound)
CGContextSetLineDash(UIGraphicsGetCurrentContext(), 0, lengths, LENGTH_OF_ARRAY)

But I see dashed lines instead of dotted lines. How can I get dotted lines instead?

like image 729
kayvee Avatar asked Feb 04 '23 04:02

kayvee


1 Answers

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);

This code should work correctly.

like image 116
Dennis Pashkov Avatar answered Feb 13 '23 07:02

Dennis Pashkov