Using ShowTextAtPoint, the displayed text is flipped

I am using the ShowTextAtPoint method for CGContext to display text in a view, but it is displayed in flip mode, does anyone know how to solve this problem? Here is the code I'm using:

ctx.SelectFont("Arial", 16f, CGTextEncoding.MacRoman); 
ctx.SetRGBFillColor(0f, 0f, 1f, 1f);
ctx.SetTextDrawingMode(CGTextDrawingMode.Fill);
ctx.ShowTextAtPoint(centerX, centerY, text);
+3
source share
2 answers

According to Quartz 2D Programming Guide - Text :

iOS , , 16-1. y . 16-2 , drawRect: iOS. MyDrawText 16-1 .

MonoTouch:

public void DrawText(string text, float x, float y)
{
    // the incomming coordinates are origin top left
    y = Bounds.Height-y;

    // push context
    CGContext c = UIGraphics.GetCurrentContext();
    c.SaveState();

    // This technique requires inversion of the screen coordinates
    // for ShowTextAtPoint
    c.TranslateCTM(0, Bounds.Height);
    c.ScaleCTM(1,-1);

    // for debug purposes, draw crosshairs at the proper location
    DrawMarker(x,y);

    // Set the font drawing parameters
    c.SelectFont("Helvetica-Bold", 12.0f, CGTextEncoding.MacRoman);
    c.SetTextDrawingMode(CGTextDrawingMode.Fill);
    c.SetFillColor(1,1,1,1);

    // Draw the text
    c.ShowTextAtPoint( x, y, text );

    // Restore context
    c.RestoreState();
}

:

public void DrawMarker(float x, float y)
{
    float SZ = 20;

    CGContext c = UIGraphics.GetCurrentContext();

    c.BeginPath();
    c.AddLines( new [] { new PointF(x-SZ,y), new PointF(x+SZ,y) });
    c.AddLines( new [] { new PointF(x,y-SZ), new PointF(x,y+SZ) });
    c.StrokePath();
}
0

, ScaleCTM TranslateCTM.

+1

All Articles