title: How to create embossed or shadow effects using Core Graphics (for finger paint)
body: <p>I have issue to implement "Emboss/Shadow effects" in my drawing.  Finger paint functionality is currently working fine with my custom <code>UIView</code> and below is my <code>drawRect</code> method code:</p>
  
  <p><strong>Edit code with all methods :</strong></p>
  
  <pre><code>- (void)drawRect:(CGRect)rect
  {
      CGPoint mid1 = midPoint(previousPoint1, previousPoint2); 
      CGPoint mid2 = midPoint(currentPoint, previousPoint1);
  
      CGContextRef context = UIGraphicsGetCurrentContext(); 
      [self.layer renderInContext:context];
  
      CGContextMoveToPoint(context, mid1.x, mid1.y);
      CGContextAddQuadCurveToPoint(context, previousPoint1.x, previousPoint1.y, mid2.x, mid2.y); 
      CGContextSetLineCap(context, kCGLineCapRound);
      CGContextSetLineWidth(context, self.lineWidth);
      CGContextSetStrokeColorWithColor(context, self.lineColor.CGColor);
      CGContextSaveGState(context);
  
      // for shadow  effects
      CGContextSetShadowWithColor(context, CGSizeMake(0, 2),3, self.lineColor.CGColor);
      CGContextStrokePath(context);
      [super drawRect:rect];
  }
  
  CGPoint midPoint(CGPoint p1, CGPoint p2)
  {
      return CGPointMake((p1.x + p2.x) * 0.5, (p1.y + p2.y) * 0.5);
  }
  
  
  -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  {
  
      UITouch *touch = [touches anyObject];
  
      previousPoint1 = [touch previousLocationInView:self];
      previousPoint2 = [touch previousLocationInView:self];
      currentPoint = [touch locationInView:self];
  
      [self touchesMoved:touches withEvent:event];
  }
  
  -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
  {
  
      UITouch *touch  = [touches anyObject];
  
      previousPoint2  = previousPoint1;
      previousPoint1  = [touch previousLocationInView:self];
      currentPoint    = [touch locationInView:self];
  
  
      // calculate mid point
      CGPoint mid1    = midPoint(previousPoint1, previousPoint2); 
      CGPoint mid2    = midPoint(currentPoint, previousPoint1);
  
      CGMutablePathRef path = CGPathCreateMutable();
      CGPathMoveToPoint(path, NULL, mid1.x, mid1.y);
      CGPathAddQuadCurveToPoint(path, NULL, previousPoint1.x, previousPoint1.y, mid2.x, mid2.y);
      CGRect bounds = CGPathGetBoundingBox(path);
      CGPathRelease(path);
  
      CGRect drawBox = bounds;
  
      //Pad our values so the bounding box respects our line width
      drawBox.origin.x        -= self.lineWidth * 2;
      drawBox.origin.y        -= self.lineWidth * 2;
      drawBox.size.width      += self.lineWidth * 4;
      drawBox.size.height     += self.lineWidth * 4;
  
      UIGraphicsBeginImageContext(drawBox.size);
      [self.layer renderInContext:UIGraphicsGetCurrentContext()];
      curImage = UIGraphicsGetImageFromCurrentImageContext();
      [curImage retain];
      UIGraphicsEndImageContext();
  
  
  
     [self setNeedsDisplayInRect:drawBox];
  
  }
  </code></pre>
  
  <p>when i have implemented this i am getting paint effects with dot dot dot ... </p>
  
  <p>See below image (which does not have any shadow or embossed effects). If you have any idea of how to add these effects, please give me some suggestion. How can i resolve this?</p>
  
  <p><img src="https://i.stack.imgur.com/yFuLJ.png" alt="enter image description here"></p>