views:

1870

answers:

2

I am using bottom left corner instead of top left to draw on iPhone using the following:

CGContextTranslateCTM(context, 0.0, 200.0); CGContextScaleCTM(context, 1.0, -1.0);

While this works fine for changing my origin to draw a chart but labeling appears upside down.

How do use my coordinate system but also get normal straight text to properly label the chart I am drawing ?

+1  A: 

Use CGContextSaveGState and CGContextRestoreGState to make sure
that the CTM scaling applies to your graphics and not your text.

Rhythmic Fistman
+1  A: 

Yes ive just recently had to solve the same problem. The trick is to briefly undo the "inversion" just before writing the labels:

    NSPoint p = NSMakePoint(x+5,5);
CGContextSaveGState(ctx);  
CGContextTranslateCTM(ctx, 0, b.origin.y+y+25); // Flip temporarily for text 
CGContextScaleCTM(ctx, 1.0, -1.0);  
[string drawAtPoint: p withAttributes:nil];    // Draw your strings
CGContextRestoreGState(ctx);                   // Flip back

Note the b.origin.y value is the height of the viewable area, x and y are the positions of the labels

Jacob