Skip to content

Instantly share code, notes, and snippets.

@PoslinskiNet
Created June 9, 2013 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PoslinskiNet/5743156 to your computer and use it in GitHub Desktop.
Save PoslinskiNet/5743156 to your computer and use it in GitHub Desktop.
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