skiasharp/samples/Basic/iOS/SkiaSharpSample/ViewController.cs
2018-01-29 17:26:14 +02:00

50 lines
1.1 KiB
C#

using System;
using UIKit;
using SkiaSharp;
using SkiaSharp.Views.iOS;
namespace SkiaSharpSample
{
public partial class ViewController : UIViewController
{
protected ViewController(IntPtr handle)
: base(handle)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
skiaView.PaintSurface += OnPaintSurface;
}
private void OnPaintSurface(object sender, SKPaintSurfaceEventArgs e)
{
// the the canvas and properties
var canvas = e.Surface.Canvas;
// get the screen density for scaling
var scale = (float)skiaView.ContentScaleFactor;
// handle the device screen density
canvas.Scale(scale);
// make sure the canvas is blank
canvas.Clear(SKColors.White);
// draw some text
var paint = new SKPaint
{
Color = SKColors.Black,
IsAntialias = true,
Style = SKPaintStyle.Fill,
TextAlign = SKTextAlign.Center,
TextSize = 24
};
var coord = new SKPoint((float)skiaView.Bounds.Width / 2, ((float)skiaView.Bounds.Height + paint.TextSize) / 2);
canvas.DrawText("SkiaSharp", coord, paint);
}
}
}