本文整理汇总了C#中CGContext.SetLineDash方法的典型用法代码示例。如果您正苦于以下问题:C# CGContext.SetLineDash方法的具体用法?C# CGContext.SetLineDash怎么用?C# CGContext.SetLineDash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGContext
的用法示例。
在下文中一共展示了CGContext.SetLineDash方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HatchGrid
protected void HatchGrid(CGContext context)
{
var hatchSize = getHatchWidth (hatchStyle);
var lineWidth = getLineWidth (hatchStyle);
initializeContext(context, hatchSize, false);
/* draw background */
drawBackground (context, backColor, hatchSize, hatchSize);
/* draw lines in the foreground color */
context.SetStrokeColor(foreColor.ToCGColor());
context.SetLineWidth(lineWidth);
context.SetLineCap(CGLineCap.Square);
hatchSize -=HALF_PIXEL_X;
float yoffset = 0;
if (hatchStyle == HatchStyle.DottedGrid)
{
yoffset = 1;
nfloat[] dash = new nfloat[] { 1, 1};
context.SetLineDash(2,dash);
}
/* draw a horizontal line */
context.MoveTo(0,yoffset);
context.AddLineToPoint(0,hatchSize);
context.StrokePath();
/* draw a vertical line */
context.MoveTo(0,hatchSize);
context.AddLineToPoint(hatchSize, hatchSize);
context.StrokePath();
}
示例2: DrawInContext
public override void DrawInContext (CGContext context)
{
// Drawing lines with a white stroke color
context.SetRGBStrokeColor(1, 1, 1, 1);
// Draw them with a 2 stroke width so they are a bit more visible.
context.SetLineWidth(2);
// Each dash entry is a run-length in the current coordinate system.
// For dash1 we demonstrate the effect of the number of entries in the dash array
// when count==2, we get length 10 drawn, length 10 skipped, etc
// when count==3, we get 10 drawn, 10 skipped, 20 draw, 10 skipped, 10 drawn, 20 skipped, etc
// and so on
float [] dash1 = new float [] {10, 10, 20, 30, 50};
// Different dash lengths
for(int i = 2; i <= 5; ++i)
{
context.SetLineDash(0, dash1, i);
context.MoveTo(10, (i - 1) * 20);
context.AddLineToPoint(310, (i - 1) * 20);
context.StrokePath();
}
// For dash2 we always use count 4, but use it to demonstrate the phase
// phase=0 starts us 0 points into the dash, so we draw 10, skip 10, draw 20, skip 20, etc.
// phase=6 starts 6 points in, so we draw 4, skip 10, draw 20, skip 20, draw 10, skip 10, etc.
// phase=12 stats us 12 points in, so we skip 8, draw 20, skip 20, draw 10, skip 10, etc.
// and so on.
float [] dash2 = {10, 10, 20, 20};
// Different dash phases
for(int i = 0; i < 10; ++i)
{
context.SetLineDash((float) i * 6, dash2, 4);
context.MoveTo(10, (float) (i + 6) * 20);
context.AddLineToPoint(310, (float)(i + 6) * 20);
context.StrokePath();
}
}
示例3: DrawLine
public static void DrawLine(CGContext context, List<PointF> points, CGColor color, float lineWidth, bool closePath, bool dashed)
{
if (points == null)
throw new NullReferenceException();
if (points.Count == 0)
throw new ArgumentException("The line must have at least one point.");
context.SaveState();
context.SetStrokeColor(color);
context.SetLineWidth(lineWidth);
context.MoveTo(points[0].X, points[0].Y);
for(int a = 1; a < points.Count; a++)
context.AddLineToPoint(points[a].X, points[a].Y);
if (dashed)
context.SetLineDash(0, new float[2] { 1, 2 }, 2);
if (closePath)
context.ClosePath();
context.StrokePath();
context.RestoreState();
}