iOS Guides | Samples

CoreGraphics.CGPathDrawingMode Enumeration

Drawing mode.

Syntax

public enum CGPathDrawingMode

Remarks

This enumeration allows the application developer to choose between showing the fill, stroke, or both of a path. Additionally, it allows the developer to choose whether to use the Core Graphics standing "non-zero winding rule" fill mode or the "even-odd rule" fill mode.

Both the "non-zero winding rule" and the "even-odd rule" decide whether to fill a pixel by considering a line drawn from the point to outside the path.

The “non-zero winding rule” mode does not fill the pixel if the path crosses that line clockwise and counterclockwise an equal number of times. If the count of clockwise versus counterclockwise crossings is non-zero, the point is considered inside the path and is filled. As the following illustration shows, this makes path direction an important consideration.

The “even-odd” rule fills a pixel if the number of paths crossed is odd. It does not take the direction of the path into account.

The following example shows a more complex situation. The top path is drawn with the "even-odd rule" (CGPathDrawingMode.EOFillStroke) while the bottom is filled with the "non-zero winding rule" (CGPathDrawingMode.FillStroke). In both cases, the path is both stroked in red and filled in green.

C# Example

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

	using (var ctxt = UIGraphics.GetCurrentContext ()) {
		ctxt.ScaleCTM (1, -1);
		ctxt.TranslateCTM (0, -Bounds.Height);
   	DrawPathWithWindingMode (ctxt, Bounds.Height / 2, CGPathDrawingMode.EOFillStroke);
	  DrawPathWithWindingMode (ctxt, 0, CGPathDrawingMode.FillStroke);
		}
}

void DrawPathWithWindingMode (CGContext ctxt, float yOffset, CGPathDrawingMode mode)
{
	var points = new PointF[] {
		new PointF (50, 50),
		new PointF (200, 50),
		new PointF (200, 100),
		new PointF (50, 100),
		new PointF (50, 50),
		new PointF (150, 50),
		new PointF (150, 150),
		new PointF (100, 150),
		new PointF (100, 25)
	};
	points = points.Select (pt => new PointF(pt.X, pt.Y += yOffset)).ToArray();
	ctxt.SetStrokeColor (UIColor.Red.CGColor);
	ctxt.SetFillColor (UIColor.Green.CGColor);
	ctxt.MoveTo (points [0].X, points [0].Y);
	for (var i = 1; i < points.Length; i++) {
		ctxt.AddLineToPoint (points [i].X, points [i].Y);
	}
	ctxt.DrawPath (mode);
}

Members

Member NameDescription
EOFillFills the path using the even-odd rule.
EOFillStrokeFills and strokes the path using the even-odd rule.
FillFills the path using the non-zero winding rule.
FillStrokeFills and strokes the path using the non-zero winding rule.
StrokeStrokes the path.

Requirements

Namespace: CoreGraphics
Assembly: Xamarin.iOS (in Xamarin.iOS.dll)
Assembly Versions: 0.0.0.0

The members of CoreGraphics.CGPathDrawingMode are listed below.

See Also: Enum

Public Fields

EOFillCGPathDrawingMode. Fills the path using the even-odd rule.
EOFillStrokeCGPathDrawingMode. Fills and strokes the path using the even-odd rule.
FillCGPathDrawingMode. Fills the path using the non-zero winding rule.
FillStrokeCGPathDrawingMode. Fills and strokes the path using the non-zero winding rule.
StrokeCGPathDrawingMode. Strokes the path.