Skip to content

Instantly share code, notes, and snippets.

@victorchee
Last active August 29, 2015 14:00
Show Gist options
  • Save victorchee/11136064 to your computer and use it in GitHub Desktop.
Save victorchee/11136064 to your computer and use it in GitHub Desktop.
iOS放射渐进视图
CGContextRef context = UIGraphicsGetCurrentContext();
size_t num_locations = 2;
CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
CGFloat components[8] = {1,1,1,1, // 中心颜色(r, g, b, alpha)
.2,.2,.2,1 // 边缘颜色};
CGFloat locations[2] = {0,1};
CGGradientRef gradient = CGGradientCreateWithColorComponents(rgb, components, locations, num_locations);
CGColorSpaceRelease(rgb);
CGRect bounds = self.bounds;
CGPoint center = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds)); // 中心发散渐进
CGContextDrawRadialGradient(context, gradient, center, 0, center, bounds.size.width, kCGGradientDrawsAfterEndLocation);
CGGradientRelease(gradient);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment