このメソッドを使用して自分自身を描画する単純なスクロール グラフがあります。このグラフにテキスト ラベルを追加する方法を探していますが、その方法が見つかりません。
私は試した:
[@"test" drawInRect: CGRectMake(0, 0, 10, 10) withFont:[UIFont systemFontOfSize:8]];
無効なコンテキスト 0x0 というエラー メッセージが表示されます。以下のコードを変更して、テキスト描画コードが正しいコンテキストを指すようにするにはどうすればよいですか?
-(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 < 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);
}