MonoTouch.UIKit.UIView.Draw Method
Draws the view within the passed-in rectangle.

Syntax

[MonoTouch.Foundation.Export("drawRect:")]
[MonoTouch.ObjCRuntime.ThreadSafe]
public virtual void Draw (System.Drawing.RectangleF rect)

Parameters

rect
The System.Drawing.RectangleF to draw.

Remarks

The UIView.Draw method should never be called directly. It is called by iOS during run loop processing. The first time through the run loop, it is called. After that, it will be called on demand whenever the view has been marked as needing display by calling UIView.SetNeedsDisplay or UIView.SetNeedsDisplayInRect(System.Drawing.RectangleF).

Core Graphics uses device independent points rather than pixels. This allows drawing code to scale between different resolutions. For example, on a Retina display, 1 point is equivalent to 2 pixels, while on non-Retina displays, 1 point corresponds to 1 pixel.

C# Example

public override void Draw (RectangleF rect)
{
    base.Draw (rect);

    var context = UIGraphics.GetCurrentContext ();

    context.SetLineWidth(4);
    UIColor.Red.SetFill ();
    UIColor.Blue.SetStroke ();

    var path = new CGPath ();

    path.AddLines(new PointF[]{
    new PointF(100,200),
    new PointF(160,100), 
    new PointF(220,200)});

    path.CloseSubpath();

    context.AddPath(path);		
    context.DrawPath(CGPathDrawingMode.FillStroke);
}
              

This can be used from a background thread.

Requirements

Namespace: MonoTouch.UIKit
Assembly: monotouch (in monotouch.dll)
Assembly Versions: 0.0.0.0