Showing posts with label CGContextDrawRadialGradient. Show all posts
Showing posts with label CGContextDrawRadialGradient. Show all posts

Friday, July 8, 2011

Draw Radial Gradient in Quartz

Here is the code snippet for that to be written inside - (void)drawRect:(CGRect)rect of UIView




    CGContextRef ctx = UIGraphicsGetCurrentContext();

    
    
    //Draw the gray Gradient
    
    CGFloat BGLocations[2] = { 0.0, 1.0 };
    CGFloat BgComponents[8] = { 0.25, 0.25, 0.25 , 1.0// Start color
       0.11, 0.11, 0.11, 1.0 }; // Mid color and End color
    CGColorSpaceRef BgRGBColorspace = CGColorSpaceCreateDeviceRGB();
    CGGradientRef bgRadialGradient = CGGradientCreateWithColorComponents(BgRGBColorspace, BgComponents, BGLocations, 2);
    
    
    CGPoint startBg = CGPointMake(250, 250); 
    CGFloat endRadius= 250;
    
    
    CGContextDrawRadialGradient(ctx, bgRadialGradient, startBg, 0, startBg, endRadius, kCGGradientDrawsAfterEndLocation);
    CGColorSpaceRelease(BgRGBColorspace);
    CGGradientRelease(bgRadialGradient);
    







Screenshot of the output