그림 16-1에서와 같이 아이폰 OS에서
, 당신은 텍스트의 순서를 현재 그래픽 컨텍스트에 변환을 적용해야이 지향한다. 이 변환 은 y 축을 반전합니다. 및 은 원점을 화면 하단의으로 변환합니다. Listing 16-2는 iOS 뷰의 drawRect : 메소드에서 그러한 변환을 적용하는 방법을 보여준다. 그런 다음이 메소드는 Listing 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();
}
당신이 사용 예를 가리시겠습니까? 감사. –