Skip to content

Instantly share code, notes, and snippets.

@bluebanboom
Created June 10, 2012 15:59
Show Gist options
  • Save bluebanboom/2906362 to your computer and use it in GitHub Desktop.
Save bluebanboom/2906362 to your computer and use it in GitHub Desktop.
Draw with gloss
- (void)drawRect:(CGRect)rect
{
// Drawing code
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(currentContext, [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.35].CGColor);
CGContextAddRect(currentContext, CGRectMake(0, 1, self.frame.size.width, 1));
CGContextFillPath(currentContext);
CGGradientRef glossGradient;
CGColorSpaceRef rgbColorspace;
size_t num_locations = 2;
CGFloat locations[2] = { 0.0, 1.0 };
CGFloat components[8] = { 1.0, 1.0, 1.0, 0.35, // Start color
1.0, 1.0, 1.0, 0.1 }; // End color
rgbColorspace = CGColorSpaceCreateDeviceRGB();
glossGradient = CGGradientCreateWithColorComponents(rgbColorspace, components, locations, num_locations);
CGRect currentBounds = self.bounds;
CGPoint topCenter = CGPointMake(CGRectGetMidX(currentBounds), 1.0f);
CGPoint midCenter = CGPointMake(CGRectGetMidX(currentBounds), CGRectGetMidY(currentBounds));
CGContextDrawLinearGradient(currentContext, glossGradient, topCenter, midCenter, 0);
CGGradientRelease(glossGradient);
CGColorSpaceRelease(rgbColorspace);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment