title: How to darken a PNG?
body: <p>I may point out that Drawing and Rendering in Objective-C is my weakness. Now, here's my problem.</p>
  
  <p>I want to add a 'Day/Night' feature to my game. It has got lots of objects on a map. Every object is a UIView containing some data in variables and some UIImageViews: the sprite, and some of the objects have a hidden ring (used to show selection).</p>
  
  <p>I want to be able to darken the content of the UIView, but I can't figure out how. The sprite is a PNG with transparency. I've just managed to add a black rectangle behind the sprite using this:</p>
  
  <pre><code>CGContextRef ctx = UIGraphicsGetCurrentContext();
  CGContextSaveGState(ctx);
  
  CGContextSetRGBFillColor(ctx, 0, 0, 0, 0.5);
  CGContextFillRect(ctx, rect);
  CGContextRestoreGState(ctx);
  </code></pre>
  
  <p>As I've read, this should be done in the drawRect method. Help please!</p>
  
  <p>If you want to understand better my scenario, the App where I'm trying to do this is called 'Kipos', at the App Store.</p>