Search code examples
iphonecore-graphicsquartz-graphicsshadowgraphic

CoreGraphics/Quartz shadows


I'm currently drawing a sinus-curve using the CoreGraphics/Quartz CGContextAddLineToPoint-function on the iPhone:

CGContextRef _context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(_context, 6.0);
CGColorSpaceRef _colorSpace = CGColorSpaceCreateDeviceRGB(); 
CGFloat _whiteColorComponents[] = {1.0, 1.0, 1.0, 1.0};
CGColorRef _color = CGColorCreate(_colorSpace, _whiteColorComponents);
CGContextSetStrokeColorWithColor(_context, _color);

CGContextMoveToPoint(_context, 0, 200);

float _increment = 1;
for (float _i = 0; _i<320; _i=_i+_increment) {
    float _sin = ((sin(_i/10) + 1) * 100) + 100;
    CGContextAddLineToPoint(_context, _i, _sin);
}

CGContextStrokePath(_context);

Now I would like to add a shadow (rather an outer-glow) to the whole path. Is this possible using Quartz (only read something about CGShading, but this seems kind of difficult)?

Thank you in advance, Alexander


Solution

  • The simplest way would be drawing to lines.

    1. Draw 'shadow' line (color1, width1)
    2. Draw normal line on top (color2, width2)