2011-03-11 24 views
3

私はCGContextのShowTextAtPointメソッドを使用してビュー内にテキストを表示しますが、フリップモードで表示されます。ここ は、私が使用するコードです:ShowTextAtPointを使用すると、表示されたテキストが反転されます

ctx.SelectFont("Arial", 16f, CGTextEncoding.MacRoman); 
ctx.SetRGBFillColor(0f, 0f, 1f, 1f); 
ctx.SetTextDrawingMode(CGTextDrawingMode.Fill); 
ctx.ShowTextAtPoint(centerX, centerY, text); 

答えて

0

:iOS版で

、あなたは図16-1に示すように配向するテキストのために、現在のグラフィックスコンテキストに変換を適用する必要があります。この変換は、y軸を逆転しますは、原点を画面の下に翻訳します。リスト16-2は、iOSビューのdrawRect:メソッドでそのような変換を適用する方法を示しています。このメソッドは、リスト16-1と同じMyDrawTextメソッドを呼び出して、同じ結果を得ます。

の方法は、これは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(); 
} 
1

あなたがScaleCTMとTranslateCTMを使用してそれを反転するグラフィックスコンテキストの現在の変換行列を操作することができます。 Quartz 2D Programming Guide - Textによると

+0

は、あなたが使用例を指していただけますか?ありがとう。 –

関連する問題