iPhone - Draw some text with CGContext : ok but... mirrored

Oliver picture Oliver · Aug 31, 2011 · Viewed 20.6k times · Source

When I draw some text using CGContext, it is drawn mirrored.

I tried to apply some transformations, then it is draw well, but then the rest of the drawing and all coordinates seems to be draw bad.

I tried to save and restore the context, before and ater drawing the text (and aplying transformation), but that does not help.

How some text must be drawn onto a View using CGContext without affecting the rest of the drawing, nor the onscreen CGPoint coords for that text ?

Answer

samfu_1 picture samfu_1 · Aug 31, 2011

Can you clarify what you mean as 'mirrored'? Here is some code for drawing some black text. It should not be 'mirrored'.

CGRect viewBounds = self.bounds;
CGContextTranslateCTM(ctx, 0, viewBounds.size.height);
CGContextScaleCTM(ctx, 1, -1);
CGContextSetRGBFillColor(ctx, 0.0, 1.0, 0.0, 1.0);
CGContextSetLineWidth(ctx, 2.0);
CGContextSelectFont(ctx, "Helvetica", 10.0, kCGEncodingMacRoman);
CGContextSetCharacterSpacing(ctx, 1.7);
CGContextSetTextDrawingMode(ctx, kCGTextFill);
CGContextShowTextAtPoint(ctx, 100.0, 100.0, "SOME TEXT", 9);