Created
December 5, 2013 14:10
-
-
Save adow/7805706 to your computer and use it in GitHub Desktop.
make radial gradient 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.2, 0.9}; | |
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); | |
myGradient = CGGradientCreateWithColorComponents (myColorspace, components, | |
locations, num_locations); | |
CGPoint myStartPoint={self.bounds.size.width/2,self.bounds.size.height/2}; | |
CGFloat myStartRadius=0, myEndRadius=self.bounds.size.width*1.5; | |
CGContextDrawRadialGradient (context, myGradient, myStartPoint, | |
myStartRadius, myStartPoint, myEndRadius, | |
kCGGradientDrawsAfterEndLocation); | |
UIImage* image=UIGraphicsGetImageFromCurrentImageContext(); | |
CGContextRestoreGState(context); | |
CGColorSpaceRelease(myColorspace); | |
CGGradientRelease(myGradient); | |
UIGraphicsEndImageContext(); | |
NSLog(@"image size:%@",NSStringFromCGSize(image.size)); | |
return image; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment