Last active
December 25, 2015 03:49
-
-
Save xdream86/6912928 to your computer and use it in GitHub Desktop.
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 | |
{ | |
CGContextRef context = UIGraphicsGetCurrentContext(); | |
CGContextSaveGState(context); | |
{ | |
size_t num_locations = 2; | |
CGFloat locations[2] = {0.1, 0.9}; // 突出一个聚焦点 | |
CGFloat colorComponents[8] = { 68.0/255.0, 68.0/255.0, 68.0/255.0, 1.0, | |
32.0/255.0, 36.0/255.0, 41.0/255.0, 1.0 }; | |
CGColorSpaceRef myColorspace = CGColorSpaceCreateDeviceRGB(); | |
CGGradientRef gradient = CGGradientCreateWithColorComponents (myColorspace, colorComponents, locations, num_locations); | |
CGPoint centerPoint = CGPointMake(self.bounds.size.width / 2.0, | |
self.bounds.size.height / 2.0); | |
// Draw the gradient | |
// 最后一个参数表明会自动填充终点圆的外部区域 | |
CGContextDrawRadialGradient(context, gradient, centerPoint, 0, centerPoint, rect.size.width / 2, (kCGGradientDrawsAfterEndLocation)); | |
CGGradientRelease(gradient); | |
CGColorSpaceRelease(myColorspace); | |
} | |
CGContextRestoreGState(context); | |
// Blend the noize texture to the background | |
CGSize textureSize = [noizeImage size]; | |
CGContextDrawTiledImage(context, CGRectMake(0, 0, textureSize.width, textureSize.height), noizeImage.CGImage); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment