Created
June 9, 2013 11:00
-
-
Save PoslinskiNet/5743156 to your computer and use it in GitHub Desktop.
Simple way how to achieve Radial Gradient View in Objective-C
This file contains 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
#import <UIKit/UIKit.h> | |
@interface RadialGradientView : UIView | |
@end |
This file contains 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
#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