11

How to add rect or any shape using Skia Sharp and apply both fill color and stroke color to that object in iOS

Devaraj
  • 138
  • 1
  • 8

1 Answers1

23

To draw both fill and stroke, you will have to do two paint operations:

// the rectangle
var rect = SKRect.Create(10, 10, 100, 100);

// the brush (fill with blue)
var paint = new SKPaint {
    Style = SKPaintStyle.Fill,
    Color = SKColors.Blue
};

// draw fill
canvas.DrawRect(rect, paint);

// change the brush (stroke with red)
paint.Style = SKPaintStyle.Stroke;
paint.Color = SKColors.Red;

// draw stroke
canvas.DrawRect(rect, paint);
Matthew
  • 4,832
  • 2
  • 29
  • 55
  • Thanks for the help @Matthew, can you help me on finding difference between drawing through UIVIew and SkiaSharp it seems both are similar. – Devaraj Mar 01 '17 at 04:48
  • There is no real difference as such. But the advantage of SkiaSharp is that the code is 100% re-usable on most platforms - servers to mobile, windows to linux. – Matthew Mar 14 '17 at 03:02