I want to write text in a way that can take any form. Right now I can draw inverted text in it:
NSArray *coordinates = ...; CGMutablePathRef pathRef = [self objectPathGivenCoordinates:coordinates]; ...
This creates the following:

I understand that iOS has an inverted coordinate system. Most solutions add these two lines before drawing:
CGContextTranslateCTM(context, 0, rect.size.height); CGContextScaleCTM(context, 1.0, -1.0);
But this produces the following:

So why does this technique not work? In every example I saw, this method is used when the text is displayed in something symmetrical or with clipping or on OS X. If we draw the text in a symmetrical form, our calls to CGContextTranslateCTM() and CGContextScaleCTM() make sense. Calling CGContextTranslateCTM(context, 0, rect.size.height) moves the beginning of the first letter up. Calling CGContextScaleCTM(context, 1, -1) changes the direction of Y. If we change the direction of Y to a symmetrical shape, it will not change. Unfortunately, my figures are not symmetrical.
Here is what I reviewed, but refused
- Draw the figures and numbers at the same scale (upside down), then flip the
UIImageView behind it somehow (1) - Do not make calls to change the scale or translate CTM. Flip the text matrix with
CGContextSetTextMatrix() so that the text is drawn from left to right, from bottom to top, and from right to top. Determine how many extra characters remain in the form after defining the line for the shape. Turn over the words (now he will draw from top to bottom, from right to left, from top to right). Add spaces for each additional character. Now for each CTLine , somehow turn the words over again (now it will draw from top to bottom, from left to right, from top to right) (2)
Why did I leave them
(1) I cannot flip my images. They should always be right.
(2) This may be redundant for a simple solution that someone knows
source share