Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MonoTouch: Custom drawing text allways draws flip text

Tags:

xamarin.ios

Inside the UIView subclass, I override the Draw sub to draw some custom text, but the text allways is drawn as flip text.

This is the code I am using:

class TextViewProblem : UIView
{
public override void Draw (RectangleF rect)
    {
        base.Draw (rect);

        CGContext g = UIGraphics.GetCurrentContext();

        UIColor.White.SetFill();

        g.SelectFont("Arial",16f,CGTextEncoding.MacRoman);

        UIColor.White.SetFill();
        g.SetTextDrawingMode(CGTextDrawingMode.Fill);
        g.ShowTextAtPoint(1,25,"Yiannis 123");



    }

}

And this is the output of this code: enter image description here

Why is the text drawn flipped?

I am running: MonoDevelop 2.4.2 iPhone Simulator 4.2 MonoTouch 3.2.6

You can download a project to reproduce this issue from this link: www.grbytes.com/downloads/TextProblem.zip

like image 469
Yiannis Mpourkelis Avatar asked Dec 21 '22 15:12

Yiannis Mpourkelis


1 Answers

The image is flipped because the coordinate system for CoreGraphics is not the same as for UIKit, you need to apply a transformation that includes flipping around the rendering (scale by x=1, y=-1) and then translate by the height (x=0, y=height).

You do this by applying the transformation to your graphics context.

like image 86
miguel.de.icaza Avatar answered May 10 '23 23:05

miguel.de.icaza