0

I am trying to draw some text in MonoMac but without success. In the provided sample the circle is drawn, but the text does not appear.

var context = NSGraphicsContext.CurrentContext.GraphicsPort;
context.SetStrokeColor (new CGColor(1.0f, 0f, 0f)); // red
context.SetLineWidth (1.0F);
context.StrokeEllipseInRect (new RectangleF(5, 5, 10, 10));
context.SetTextDrawingMode(CGTextDrawingMode.Stroke);
context.TextPosition = new PointF(0f, 0f);
context.ShowText("My text"); // is not shown

Thanks

tomitrescak
  • 1,072
  • 12
  • 22

2 Answers2

0

You just need to specify the font you would like to use.

public override void DrawRect (RectangleF dirtyRect)
{
    var context = NSGraphicsContext.CurrentContext.GraphicsPort;

    context.SetStrokeColor (new CGColor(1.0f, 0f, 0f)); // red
    context.SetLineWidth (1.0F);
    context.StrokeEllipseInRect (new RectangleF(5, 5, 10, 10));
    context.SetTextDrawingMode(CGTextDrawingMode.Stroke);
    context.TextPosition = new PointF(0f, 0f);
    context.SelectFont ("Arial", 5, CGTextEncoding.MacRoman);
    context.ShowText("My text");
}
Keith Maurino
  • 3,374
  • 10
  • 40
  • 48
0

you just need to rewrite drawRect.

public override void DrawRect (RectangleF dirtyRect)
    {
        NSString s = new NSString ("test");
        s.DrawString (new PointF(25,100), new NSDictionary ());
    }

if you want to customize it, here's a good reference.

vlady
  • 153
  • 6