Guest User

Untitled

a guest
Sep 25th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. //1. create vars
  2. float increment = 1.0f / (colours.count-1);
  3. CGFloat * locations = (CGFloat *)malloc((int)colours.count*sizeof(CGFloat));
  4. CFMutableArrayRef mref = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
  5.  
  6. //2. go through the colours, creating cgColors and locations
  7. for (int n = 0; n < colours.count; n++){
  8. CFArrayAppendValue(mref, (id)[colours[n] CGColor]);
  9. locations[n]=(n*increment);
  10. }
  11.  
  12. //3. create gradient
  13. CGContextRef ref = UIGraphicsGetCurrentContext();
  14. CGColorSpaceRef spaceRef = CGColorSpaceCreateDeviceRGB();
  15. CGGradientRef gradientRef = CGGradientCreateWithColors(spaceRef, mref, locations);
  16.  
  17. if (isHorizontal){
  18. CGContextDrawLinearGradient(ref, gradientRef, CGPointMake(0.0, 0.0), CGPointMake(self.frame.size.width, 0.0), kCGGradientDrawsAfterEndLocation);
  19. } else if (isDiagonal) {
  20. CGContextDrawLinearGradient(ref, gradientRef, CGPointMake(0.0, 0.0), CGPointMake(self.frame.size.width, self.frame.size.height), kCGGradientDrawsAfterEndLocation);
  21. } else {
  22. CGContextDrawLinearGradient(ref, gradientRef, CGPointMake(0.0, 0.0), CGPointMake(0.0, self.frame.size.height), kCGGradientDrawsAfterEndLocation);
  23. }
  24.  
  25. CGContextRelease(ref); //ISSUE
  26. CGColorSpaceRelease(spaceRef);
  27. CGGradientRelease(gradientRef);
Add Comment
Please, Sign In to add comment