public override void DrawInContext(CGContext context)
    {
        // Drawing with a white stroke color
        context.SetRGBStrokeColor(1, 1, 1, 1);
        // And drawing with a blue fill color
        context.SetRGBFillColor(0, 0, 1, 1);
        // Draw them with a 2 stroke width so they are a bit more visible.
        context.SetLineWidth(2);

        // Add Rect to the current path, then stroke it
        context.AddRect(new RectangleF(30, 30, 60, 60));
        context.StrokePath();

        // Stroke Rect convenience that is equivalent to above
        context.StrokeRect(new RectangleF(30, 120, 60, 60));

        // Stroke rect convenience equivalent to the above, plus a call to context.SetLineWidth ().
        context.StrokeRectWithWidth(new RectangleF(30, 210, 60, 60), 10);
        // Demonstate the stroke is on both sides of the path.
        context.SaveState();
        context.SetRGBStrokeColor(1, 0, 0, 1);
        context.StrokeRectWithWidth(new RectangleF(30, 210, 60, 60), 2);
        context.RestoreState();

        var rects = new RectangleF []
        {
            new RectangleF(120, 30, 60, 60),
            new RectangleF(120, 120, 60, 60),
            new RectangleF(120, 210, 60, 60),
        };

        // Bulk call to add rects to the current path.
        context.AddRects(rects);
        context.StrokePath();

        // Create filled rectangles via two different paths.
        // Add/Fill path
        context.AddRect(new RectangleF(210, 30, 60, 60));
        context.FillPath();
        // Fill convienience.
        context.FillRect(new RectangleF(210, 120, 60, 60));
    }
	public override void DrawInContext (CGContext context)
	{
		// Drawing with a white stroke color
		context.SetRGBStrokeColor (1, 1, 1, 1);
		// And drawing with a blue fill color
		context.SetRGBFillColor (0, 0, 1, 1);
		// Draw them with a 2 stroke width so they are a bit more visible.
		context.SetLineWidth (2);
		
		// Add Rect to the current path, then stroke it
		context.AddRect (new RectangleF (30, 30, 60, 60));
		context.StrokePath ();
		
		// Stroke Rect convenience that is equivalent to above
		context.StrokeRect (new RectangleF (30, 120, 60, 60));
		
		// Stroke rect convenience equivalent to the above, plus a call to context.SetLineWidth ().
		context.StrokeRectWithWidth (new RectangleF (30, 210, 60, 60), 10);
		// Demonstate the stroke is on both sides of the path.
		context.SaveState ();
		context.SetRGBStrokeColor (1, 0, 0, 1);
		context.StrokeRectWithWidth (new RectangleF (30, 210, 60, 60), 2);
		context.RestoreState ();
		
		var rects = new RectangleF []
		{
			new RectangleF (120, 30, 60, 60),
			new RectangleF (120, 120, 60, 60),
			new RectangleF (120, 210, 60, 60),
		};
		// Bulk call to add rects to the current path.
		context.AddRects (rects);
		context.StrokePath ();
		
		// Create filled rectangles via two different paths.
		// Add/Fill path
		context.AddRect (new RectangleF (210, 30, 60, 60));
		context.FillPath ();
		// Fill convienience.
		context.FillRect (new RectangleF (210, 120, 60, 60));
	}	
    public override void DrawInContext(CGContext context)
    {
        // The clipping rects we plan to use, which also defines the location and span of each gradient
        var clips = new RectangleF []
        {
            new RectangleF(10, 30, 60, 90),
            new RectangleF(90, 30, 60, 90),
            new RectangleF(170, 30, 60, 90),
            new RectangleF(250, 30, 60, 90),
            new RectangleF(30, 140, 120, 120),
            new RectangleF(170, 140, 120, 120),
            new RectangleF(30, 280, 120, 120),
            new RectangleF(170, 280, 120, 120),
        };

        // Linear Gradients
        PointF start, end;

        // Clip to area to draw the gradient, and draw it. Since we are clipping, we save the graphics state
        // so that we can revert to the previous larger area.
        context.SaveState();
        context.ClipToRect(clips[0]);

        // A linear gradient requires only a starting & ending point.
        // The colors of the gradient are linearly interpolated along the line segment connecting these two points
        // A gradient location of 0 means that color is expressed fully at the 'start' point
        // a location of 1 means that color is expressed fully at the 'end' point.
        // The gradient fills outwards perpendicular to the line segment connectiong start & end points
        // (which is why we need to clip the context, or the gradient would fill beyond where we want it to).
        // The gradient options (last) parameter determines what how to fill the clip area that is "before" and "after"
        // the line segment connecting start & end.
        start = demoLGStart(clips[0]);
        end   = demoLGEnd(clips[0]);
        context.DrawLinearGradient(gradient, start, end, 0);
        context.RestoreState();

        // Same as above for each combination of CGGradientDrawingOptions.DrawsBeforeStartLocation & CGGradientDrawingOptions.DrawsAfterEndLocation

        context.SaveState();
        context.ClipToRect(clips[1]);
        start = demoLGStart(clips[1]);
        end   = demoLGEnd(clips[1]);
        context.DrawLinearGradient(gradient, start, end, CGGradientDrawingOptions.DrawsBeforeStartLocation);
        context.RestoreState();

        context.SaveState();
        context.ClipToRect(clips[2]);
        start = demoLGStart(clips[2]);
        end   = demoLGEnd(clips[2]);
        context.DrawLinearGradient(gradient, start, end, CGGradientDrawingOptions.DrawsAfterEndLocation);
        context.RestoreState();

        context.SaveState();
        context.ClipToRect(clips[3]);
        start = demoLGStart(clips[3]);
        end   = demoLGEnd(clips[3]);
        context.DrawLinearGradient(gradient, start, end, CGGradientDrawingOptions.DrawsBeforeStartLocation | CGGradientDrawingOptions.DrawsAfterEndLocation);
        context.RestoreState();

        // Radial Gradients

        float startRadius, endRadius;

        // Clip to area to draw the gradient, and draw it. Since we are clipping, we save the graphics state
        // so that we can revert to the previous larger area.
        context.SaveState();
        context.ClipToRect(clips[4]);

        // A radial gradient requires a start & end point as well as a start & end radius.
        // Logically a radial gradient is created by linearly interpolating the center, radius and color of each
        // circle using the start and end point for the center, start and end radius for the radius, and the color ramp
        // inherant to the gradient to create a set of stroked circles that fill the area completely.
        // The gradient options specify if this interpolation continues past the start or end points as it does with
        // linear gradients.
        start       = end = demoRGCenter(clips[4]);
        startRadius = demoRGInnerRadius(clips[4]);
        endRadius   = demoRGOuterRadius(clips[4]);
        context.DrawRadialGradient(gradient, start, startRadius, end, endRadius, 0);
        context.RestoreState();

        // Same as above for each combination of CGGradientDrawingOptions.DrawsBeforeStartLocation & CGGradientDrawingOptions.DrawsAfterEndLocation

        context.SaveState();
        context.ClipToRect(clips[5]);
        start       = end = demoRGCenter(clips[5]);
        startRadius = demoRGInnerRadius(clips[5]);
        endRadius   = demoRGOuterRadius(clips[5]);
        context.DrawRadialGradient(gradient, start, startRadius, end, endRadius, CGGradientDrawingOptions.DrawsBeforeStartLocation);
        context.RestoreState();

        context.SaveState();
        context.ClipToRect(clips[6]);
        start       = end = demoRGCenter(clips[6]);
        startRadius = demoRGInnerRadius(clips[6]);
        endRadius   = demoRGOuterRadius(clips[6]);
        context.DrawRadialGradient(gradient, start, startRadius, end, endRadius, CGGradientDrawingOptions.DrawsAfterEndLocation);
        context.RestoreState();

        context.SaveState();
        context.ClipToRect(clips[7]);
        start       = end = demoRGCenter(clips[7]);
        startRadius = demoRGInnerRadius(clips[7]);
        endRadius   = demoRGOuterRadius(clips[7]);
        context.DrawRadialGradient(gradient, start, startRadius, end, endRadius, CGGradientDrawingOptions.DrawsBeforeStartLocation | CGGradientDrawingOptions.DrawsAfterEndLocation);
        context.RestoreState();

        // Show the clipping areas
        context.SetLineWidth(2);
        context.SetRGBStrokeColor(1, 0, 0, 1);
        context.AddRects(clips);
        context.StrokePath();
    }
    public override void DrawInContext(CGContext context)
    {
        // The clipping rects we plan to use, which also defines the location and span of each gradient
        var clips = new RectangleF []
        {
            new RectangleF(10, 30, 60, 90),
            new RectangleF(90, 30, 60, 90),
            new RectangleF(170, 30, 60, 90),
            new RectangleF(250, 30, 60, 90),
            new RectangleF(30, 140, 120, 120),
            new RectangleF(170, 140, 120, 120),
            new RectangleF(30, 280, 120, 120),
            new RectangleF(170, 280, 120, 120),
        };

        // Linear Gradients
        PointF start, end;

        // Clip to area to draw the gradient, and draw it. Since we are clipping, we save the graphics state
        // so that we can revert to the previous larger area.
        context.SaveState();
        context.ClipToRect(clips[0]);

        // A linear gradient requires only a starting & ending point.
        // The colors of the gradient are linearly interpolated along the line segment connecting these two points
        // A gradient location of 0 means that color is expressed fully at the 'start' point
        // a location of 1 means that color is expressed fully at the 'end' point.
        // The gradient fills outwards perpendicular to the line segment connectiong start & end points
        // (which is why we need to clip the context, or the gradient would fill beyond where we want it to).
        // The gradient options (last) parameter determines what how to fill the clip area that is "before" and "after"
        // the line segment connecting start & end.
        start = demoLGStart(clips[0]);
        end = demoLGEnd(clips[0]);
        context.DrawLinearGradient(gradient, start, end, 0);
        context.RestoreState();

        // Same as above for each combination of CGGradientDrawingOptions.DrawsBeforeStartLocation & CGGradientDrawingOptions.DrawsAfterEndLocation

        context.SaveState();
        context.ClipToRect(clips[1]);
        start = demoLGStart(clips[1]);
        end = demoLGEnd(clips[1]);
        context.DrawLinearGradient(gradient, start, end, CGGradientDrawingOptions.DrawsBeforeStartLocation);
        context.RestoreState();

        context.SaveState();
        context.ClipToRect(clips[2]);
        start = demoLGStart(clips[2]);
        end = demoLGEnd(clips[2]);
        context.DrawLinearGradient(gradient, start, end, CGGradientDrawingOptions.DrawsAfterEndLocation);
        context.RestoreState();

        context.SaveState();
        context.ClipToRect(clips[3]);
        start = demoLGStart(clips[3]);
        end = demoLGEnd(clips[3]);
        context.DrawLinearGradient(gradient, start, end, CGGradientDrawingOptions.DrawsBeforeStartLocation | CGGradientDrawingOptions.DrawsAfterEndLocation);
        context.RestoreState();

        // Radial Gradients

        float startRadius, endRadius;

        // Clip to area to draw the gradient, and draw it. Since we are clipping, we save the graphics state
        // so that we can revert to the previous larger area.
        context.SaveState();
        context.ClipToRect(clips[4]);

        // A radial gradient requires a start & end point as well as a start & end radius.
        // Logically a radial gradient is created by linearly interpolating the center, radius and color of each
        // circle using the start and end point for the center, start and end radius for the radius, and the color ramp
        // inherant to the gradient to create a set of stroked circles that fill the area completely.
        // The gradient options specify if this interpolation continues past the start or end points as it does with
        // linear gradients.
        start = end = demoRGCenter(clips[4]);
        startRadius = demoRGInnerRadius(clips[4]);
        endRadius = demoRGOuterRadius(clips[4]);
        context.DrawRadialGradient(gradient, start, startRadius, end, endRadius, 0);
        context.RestoreState();

        // Same as above for each combination of CGGradientDrawingOptions.DrawsBeforeStartLocation & CGGradientDrawingOptions.DrawsAfterEndLocation

        context.SaveState();
        context.ClipToRect(clips[5]);
        start = end = demoRGCenter(clips[5]);
        startRadius = demoRGInnerRadius(clips[5]);
        endRadius = demoRGOuterRadius(clips[5]);
        context.DrawRadialGradient(gradient, start, startRadius, end, endRadius, CGGradientDrawingOptions.DrawsBeforeStartLocation);
        context.RestoreState();

        context.SaveState();
        context.ClipToRect(clips[6]);
        start = end = demoRGCenter(clips[6]);
        startRadius = demoRGInnerRadius(clips[6]);
        endRadius = demoRGOuterRadius(clips[6]);
        context.DrawRadialGradient(gradient, start, startRadius, end, endRadius, CGGradientDrawingOptions.DrawsAfterEndLocation);
        context.RestoreState();

        context.SaveState();
        context.ClipToRect(clips[7]);
        start = end = demoRGCenter(clips[7]);
        startRadius = demoRGInnerRadius(clips[7]);
        endRadius = demoRGOuterRadius(clips[7]);
        context.DrawRadialGradient(gradient, start, startRadius, end, endRadius, CGGradientDrawingOptions.DrawsBeforeStartLocation | CGGradientDrawingOptions.DrawsAfterEndLocation);
        context.RestoreState();

        // Show the clipping areas
        context.SetLineWidth(2);
        context.SetRGBStrokeColor(1, 0, 0, 1);
        context.AddRects(clips);
        context.StrokePath();
    }