title: How do i do drawrect type stuff outside of drawrect?
body: <p>I have a UIView-based class called Icon. In there, I want to have code similar to this:</p>
  
  <pre><code>UIView *finalView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
  finalView.backgroundColor = [UIColor redColor];
  
  UIGraphicsBeginImageContext(finalView.bounds.size);
  [finalView.layer renderInContext:UIGraphicsGetCurrentContext()];
  UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();
  </code></pre>
  
  <p>The problem is, i don't want to have to put it in drawRect because that's called when my app makes each Icon in another view. How can i put this sort of code somewhere else in my Icon class? I tried putting it in 1 place and it gave me:</p>
  
  <pre><code>CGContextSaveGState: invalid context 0x0
  CGContextSetAlpha: invalid context 0x0
  CGContextSaveGState: invalid context 0x0
  CGContextSetFillColorWithColor: invalid context 0x0
  CGContextAddRect: invalid context 0x0
  CGContextDrawPath: invalid context 0x0
  CGContextRestoreGState: invalid context 0x0
  CGContextRestoreGState: invalid context 0x0
  </code></pre>