Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple way how to achieve Radial Gradient View in Objective-C
#import <UIKit/UIKit.h>
@interface RadialGradientView : UIView
@end
#import "RadialGradientView.h"
@implementation RadialGradientView
- (void)drawRect:(CGRect)rect
{
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGGradientRef glossGradient;
CGColorSpaceRef rgbColorspace;
size_t num_locations = 2;
CGFloat locations[2] = { 0.0, 1.0 };
CGFloat components[8] = {
0.1, 0.1, 0.1, 1, // Start color
0.00, 0.00, 0.00, 1 // End color
};
rgbColorspace = CGColorSpaceCreateDeviceRGB();
glossGradient = CGGradientCreateWithColorComponents(rgbColorspace, components, locations, num_locations);
CGRect currentBounds = self.bounds;
CGPoint midCenter = CGPointMake(CGRectGetMidX(currentBounds), CGRectGetMidY(currentBounds));
CGContextDrawRadialGradient(currentContext, glossGradient, midCenter, 0, midCenter, 400, kCGGradientDrawsBeforeStartLocation);
CGGradientRelease(glossGradient);
CGColorSpaceRelease(rgbColorspace);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.