Skip to content

Instantly share code, notes, and snippets.

@ragingprodigy
Created April 12, 2017 01:21
Show Gist options
  • Select an option

  • Save ragingprodigy/a30904f8341334e849c96475f7d05eea to your computer and use it in GitHub Desktop.

Select an option

Save ragingprodigy/a30904f8341334e849c96475f7d05eea to your computer and use it in GitHub Desktop.
Radial Gradient Implementation - Objective C
@implementation OORadialGradientView
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing Code
CGContextRef context = UIGraphicsGetCurrentContext();
// Draw A Gradient from yellow to Orange
NSArray *colors = [NSArray arrayWithObjects:(id)[UIColor yellowColor].CGColor, (id)[UIColor orangeColor].CGColor, nil];
CGColorSpaceRef myColorspace=CGColorSpaceCreateDeviceRGB();
CGGradientRef myGradient = CGGradientCreateWithColors(myColorspace, (CFArrayRef) colors, nil);
double circleWidth = self.viewForBaselineLayout.frame.size.width;
double circleHeight = self.viewForBaselineLayout.frame.size.height;
CGPoint theCenter = CGPointMake(circleWidth/2, circleHeight/2);
// Account for orientation changes
double radius = circleHeight;
if (circleHeight < circleWidth) {
radius = circleWidth;
}
CGGradientDrawingOptions options = kCGGradientDrawsBeforeStartLocation;
CGContextDrawRadialGradient(context, myGradient, theCenter, 0.0, theCenter, radius/1.3, options);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment