IPhone - draw text using CGContext: ok, but ... mirror

When I draw text using a CGContext, it is mirrored.

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

I tried to save and restore the context, before and after drawing the text (and approaching the transformation), but this does not help.

How should some text be drawn in a view using a CGContext without affecting the rest of the drawing, as well as on-screen CGPoint coordinates for that text?

+8
text iphone cocoa-touch core-graphics transformation
source share
2 answers

Can you clarify what you mean by mirroring? Here is some code for drawing black text. It does not have to be "mirror".

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); 
+12
source share

I think you need to undo the text matrix:

 CGAffineTransform transform = CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0.0, 0.0); CGContextSetTextMatrix(context, transform); 
+8
source share

All Articles