Posted By

mlecho on 04/23/11


Tagged

gradient


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

dvel


CGGradient2


 / Published in: Objective C
 

  1. CGContextRef ctx = UIGraphicsGetCurrentContext();
  2.  
  3. CGContextSaveGState(ctx);
  4. CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
  5. CGFloat colors [] = {
  6. 0.7,0.0,0.0,1.0,
  7. 1.0,0.0,0.0,1.0
  8. } ;
  9.  
  10. CGFloat locations[] = {0.5,0.0};
  11. CGGradientRef gradient = CGGradientCreateWithColorComponents(colorspace, colors, locations, 2);
  12. CGColorSpaceRelease(colorspace);
  13. CGContextAddRect(ctx, rect);
  14. CGContextDrawLinearGradient(ctx, gradient, CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect)),
  15. CGPointMake(CGRectGetMidX(rect), CGRectGetMaxY(rect)),0);
  16. CGGradientRelease(gradient);
  17. CGContextRestoreGState(ctx);

Report this snippet  

You need to login to post a comment.