Ian Vink
Ian Vink

Reputation: 68830

MonoTouch.Dialog: Upside down text in Section Header View

I am using MonoTouch.Dialog and creating a custom Section HeaderView. The Text renders upside down. What am I missing?

screenshot

public class SectionHeader: UIView
{
    string title;

    public SectionHeader (string Title): base(new RectangleF(0,0,320,40))
    {
        title = Title;
    }

    public override void Draw (RectangleF rect)
    {

        var topleft = new PointF (0, 0);
        var bottomright = new PointF (this.Frame.Width, this.Frame.Height);

        var context = UIGraphics.GetCurrentContext ();
        using (var cs = CGColorSpace.CreateDeviceRGB ())
        {
            using (var gradient = new CGGradient (cs, new float [] { 61f/255f, 1f/255f, 22f/255f, 1.0f, 1.0f, 1.0f,1.0f,1.0f }, new float [] { 0, 1 }))
            {
                context.DrawLinearGradient (gradient, topleft, bottomright, 0);
            }
        }

        context.SetFillColor (1, 1, 1, 1);
        context.SetTextDrawingMode (CGTextDrawingMode.Fill);
        context.TranslateCTM (0, 0);        
        context.SelectFont ("Helvetica", 20f, CGTextEncoding.MacRoman);
        context.ShowTextAtPoint (20, 20, title);
        context.StrokePath();   
    }
}

Upvotes: 2

Views: 345

Answers (1)

poupou
poupou

Reputation: 43553

UIKit (iOS) and CoreGraphics (iOS and OSX) have different coordinate systems. See this link for details (and graphics).

UPDATE

That should fix it:

context.ScaleCTM (1.0f, -1.0f);

Upvotes: 2

Related Questions