Created
June 10, 2012 15:59
-
-
Save bluebanboom/2906362 to your computer and use it in GitHub Desktop.
Draw with gloss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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