Created
January 2, 2014 01:10
-
-
Save dlo/8213579 to your computer and use it in GitHub Desktop.
Draw a linear gradient 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
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); | |
CGFloat locations[] = { 0.0, 1.0 }; | |
NSArray *colors = @[(__bridge id)HEX(0xC9C9CEFF).CGColor, (__bridge id)[UIColor whiteColor].CGColor]; | |
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)colors, locations); | |
UIGraphicsBeginImageContext(CGSizeMake(1, 32)); | |
CGContextRef context = UIGraphicsGetCurrentContext(); | |
CGContextDrawLinearGradient(context, gradient, CGPointMake(0, 0), CGPointMake(0, 32), 0); | |
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment