Skip to content

Instantly share code, notes, and snippets.

@0xPr0xy
Created February 24, 2014 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xPr0xy/9187610 to your computer and use it in GitHub Desktop.
Save 0xPr0xy/9187610 to your computer and use it in GitHub Desktop.
//
// Change the following piece of code
//
CGContextSaveGState(context);
CGContextClip(context);
if (_privateGradientBool == YES) {
CGGradientRef gradient; // Gradient for the fill.
CGColorSpaceRef colorSpace;
size_t num_locations = 2;
CGFloat locations[2] = {0.0f, 1.0f};
CGFloat components[8] = GRADIENT_FILL;
colorSpace = CGColorSpaceCreateDeviceRGB();
gradient = CGGradientCreateWithColorComponents(colorSpace, components, locations, num_locations);
CGPoint startPoint, endPoint;
startPoint.x = OFFSET_X;
startPoint.y = GRAPH_HEIGHT - OFFSET_Y;
endPoint.x = OFFSET_X;
endPoint.y = OFFSET_Y;
CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
CGContextRestoreGState(context);
CGColorSpaceRelease(colorSpace);
CGGradientRelease(gradient);
}
//
// To this
//
if (_privateGradientBool == YES) {
CGContextSaveGState(context);
CGContextClip(context);
CGGradientRef gradient; // Gradient for the fill.
CGColorSpaceRef colorSpace;
size_t num_locations = 2;
CGFloat locations[2] = {0.0f, 1.0f};
CGFloat components[8] = GRADIENT_FILL;
colorSpace = CGColorSpaceCreateDeviceRGB();
gradient = CGGradientCreateWithColorComponents(colorSpace, components, locations, num_locations);
CGPoint startPoint, endPoint;
startPoint.x = OFFSET_X;
startPoint.y = GRAPH_HEIGHT - OFFSET_Y;
endPoint.x = OFFSET_X;
endPoint.y = OFFSET_Y;
CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
CGContextRestoreGState(context);
CGColorSpaceRelease(colorSpace);
CGGradientRelease(gradient);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment