alecnash
alecnash

Reputation: 1768

Monotouch add border to gradient

I am trying to add borders to a gradient button:

var c = bdPencil.ColorMain;
Context.SetLineWidth(bdPencil.Width);
Context.SetStrokeColor(c.R, c.G, c.B, c.A);
Context.Clip();
CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();
CGGradient gradient = new CGGradient(colorSpace, colors, 
new float[]{ 0, 1 });
Context.DrawLinearGradient(gradient, new PointF((float)r.CenterX, (float)r.Top), new PointF((float)r.CenterX, (float)r.Bottom), 
CGGradientDrawingOptions.DrawsAfterEndLocation);
Context.RestoreState();

and it is not working. Everything is working if I do the same thing with a solid color:

  var c = bdPencil.ColorMain;
  Context.SetLineWidth(bdPencil.Width);
  Context.SetStrokeColor(c.R, c.G, c.B, c.A);
  var g = bgPencil.ColorMain;
  Context.SetFillColor(g.R, g.G, g.B, g.A);
  Context.DrawPath(CGPathDrawingMode.FillStroke);

When I am trying to stroke the path after the DrawLinearGradinet nothing happens. I suppose I need something like GradientStroke but I can't find it.

Any idea why?

Upvotes: 0

Views: 363

Answers (1)

alecnash
alecnash

Reputation: 1768

The mistake is that I tried doing everything with the context. I drew a path, stroked it and then I drew the gradient and it worked.

Upvotes: 1

Related Questions