Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1. create vars
- float increment = 1.0f / (colours.count-1);
- CGFloat * locations = (CGFloat *)malloc((int)colours.count*sizeof(CGFloat));
- CFMutableArrayRef mref = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
- //2. go through the colours, creating cgColors and locations
- for (int n = 0; n < colours.count; n++){
- CFArrayAppendValue(mref, (id)[colours[n] CGColor]);
- locations[n]=(n*increment);
- }
- //3. create gradient
- CGContextRef ref = UIGraphicsGetCurrentContext();
- CGColorSpaceRef spaceRef = CGColorSpaceCreateDeviceRGB();
- CGGradientRef gradientRef = CGGradientCreateWithColors(spaceRef, mref, locations);
- if (isHorizontal){
- CGContextDrawLinearGradient(ref, gradientRef, CGPointMake(0.0, 0.0), CGPointMake(self.frame.size.width, 0.0), kCGGradientDrawsAfterEndLocation);
- } else if (isDiagonal) {
- CGContextDrawLinearGradient(ref, gradientRef, CGPointMake(0.0, 0.0), CGPointMake(self.frame.size.width, self.frame.size.height), kCGGradientDrawsAfterEndLocation);
- } else {
- CGContextDrawLinearGradient(ref, gradientRef, CGPointMake(0.0, 0.0), CGPointMake(0.0, self.frame.size.height), kCGGradientDrawsAfterEndLocation);
- }
- CGContextRelease(ref); //ISSUE
- CGColorSpaceRelease(spaceRef);
- CGGradientRelease(gradientRef);
Add Comment
Please, Sign In to add comment