: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();
}
は、あなたが使用例を指していただけますか?ありがとう。 –