Created
April 12, 2017 01:21
-
-
Save ragingprodigy/a30904f8341334e849c96475f7d05eea to your computer and use it in GitHub Desktop.
Radial Gradient Implementation - Objective C
This file contains hidden or 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
| @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