title: iPhone - How do you color an image?
body: <p>I would love to know how to color an image (make a white .png red, for example). I have seen various suggestions but never any confirmation that this is actually possible. I have tried this:</p>
  
  <pre><code>-(UIImage *)colorizeImage:(UIImage *)baseImage color:(UIColor *)theColor {
      UIGraphicsBeginImageContext(baseImage.size);
  
      CGContextRef ctx = UIGraphicsGetCurrentContext();
      CGRect area = CGRectMake(0, 0, baseImage.size.width, baseImage.size.height);
  
      CGContextScaleCTM(ctx, 1, -1);
      CGContextTranslateCTM(ctx, 0, -area.size.height);
      CGContextSaveGState(ctx);
      CGContextClipToMask(ctx, area, baseImage.CGImage);
      [theColor set];
      CGContextFillRect(ctx, area);
      CGContextRestoreGState(ctx);
      CGContextSetBlendMode(ctx, kCGBlendModeNormal);
      CGContextDrawImage(ctx, area, baseImage.CGImage);
      UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
      UIGraphicsEndImageContext();
      return newImage;
  }
  
  myImageView.image = [self colorizeImage:[UIImage imageNamed:@"whiteImage.png"] color:[UIColor redColor]];
  </code></pre>
  
  <p>But it doesn't work - the image is still white on the screen.</p>