title: iPhone iOS how to draw text on a CALayer using drawLayer:inContext:?
body: <p>I have a simple scrolling graph which uses this method to draw itself. I'm looking for a way to add text label to this graph, but cannot find how to do this. </p>
  
  <p>I tried:</p>
  
  <pre><code>[@"test" drawInRect: CGRectMake(0, 0, 10, 10) withFont:[UIFont systemFontOfSize:8]];
  </code></pre>
  
  <p>and I get error messages saying invalid context 0x0. <strong>How do I modify the code below to point the text drawing code to the correct context?</strong></p>
  
  <pre><code>-(void)drawLayer:(CALayer*)l inContext:(CGContextRef)context
  {
      // Fill in the background
      CGContextSetFillColorWithColor(context, graphBackgroundColor());
      CGContextFillRect(context, layer.bounds);
  
      // Draw the grid lines
  //  DrawGridlines(context, 0.0, 32.0);
  
      // Draw the graph
      CGPoint lines[64];
      int i;
      // X
      for(i = 0; i &lt; 32; ++i)
      {
          lines[i*2].x = i;
          lines[i*2].y = -(xhistory[i] * 480.0)-10;
          lines[i*2+1].x = i + 1;
          lines[i*2+1].y = -(xhistory[i+1] * 480.0)-10;
      }
  
      CGContextSetStrokeColorWithColor(context, graphZColor());
      CGContextStrokeLineSegments(context, lines, 64);
  }
  </code></pre>