title: Drawing a dashed line with CGContextSetLineDash
body: <p>I'm trying to draw a dashed line with <code>CGContextSetLineDash</code>.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>float dashPhase = 0.0;
  float dashLengths[] = {30, 30};
  CGContextSetLineDash(context, dashPhase, dashLengths, 20.0);
  self.previousPoint2 = self.previousPoint1;
  self.previousPoint1 = previous;
  self.currentPoint = current;
  
  self.mid1 = [self pointBetween:self.previousPoint1 andPoint:self.previousPoint2];
  self.mid2 = [self pointBetween:self.currentPoint andPoint:self.previousPoint1];
  
  UIBezierPath* newPath = [UIBezierPath bezierPath];
  
  [newPath moveToPoint:self.mid1];
  [newPath addLineToPoint:self.mid2];
  [newPath setLineWidth:self.brushSize];
  </code></pre>
  
  <p>However, if I draw slowly, they dashed lines do not appear (see top of image below) but if I draw quickly, they do appear (see bottom of image below).</p>
  
  <p><img src="https://i.stack.imgur.com/1pjMP.png" alt="enter image description here"></p>
  
  <p>Why is this happening?</p>