Created
December 5, 2013 06:48
-
-
Save adow/7801165 to your computer and use it in GitHub Desktop.
Make a line graident image
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
-(UIImage*)makeGradientImage{ | |
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 1.0f); | |
CGContextRef context=UIGraphicsGetCurrentContext(); | |
CGContextSaveGState(context); | |
CGGradientRef myGradient; | |
CGColorSpaceRef myColorspace; | |
size_t num_locations = 2; | |
CGFloat locations[2] = { 0.0, 1.0 }; | |
CGFloat components[8] = { 0.0,0.0,0.0, 0.0, // Start color | |
0.0,0.0,0.0,1.0}; // End color | |
myColorspace = CGColorSpaceCreateDeviceRGB(); | |
myGradient = CGGradientCreateWithColorComponents (myColorspace, components, | |
locations, num_locations); | |
CGContextDrawLinearGradient(context, myGradient, CGPointMake(self.bounds.size.width/2, 100.0f), CGPointMake(self.bounds.size.width/2, self.bounds.size.height-100.0f), kCGGradientDrawsAfterEndLocation); | |
UIImage* image=UIGraphicsGetImageFromCurrentImageContext(); | |
CGContextRestoreGState(context); | |
CGColorSpaceRelease(myColorspace); | |
CGGradientRelease(myGradient); | |
UIGraphicsEndImageContext(); | |
return image; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment