Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 75885

NGraphics non default Font

$
0
0

I'm using NControl/NGraphics to draw text on a Content Page. I'd like to use a custom TTF font file and don't know how or if possible.

I've tried setting the font to any of the ones installed in my device with no luck. Has anybody been able to draw text using NGraphics using a non default font?

public override void Draw(NGraphics.ICanvas canvas, NGraphics.Rect rect)
{
    string text = "Some text";
    string fontFile = "Roboto-Italic.ttf";  // Found in Android System/fonts (better if using file from Assets though)
    NGraphics.Font MyFont = new NGraphics.Font(fontFile, 24);
    NGraphics.Size ts = canvas.MeasureText(text, MyFont);
    NGraphics.Point p = new NGraphics.Point((rect.Width - ts.Width) / 2, (rect.Height - ts.Height) / 2); 
    canvas.DrawText(text, p, Font, null);
}

Viewing all articles
Browse latest Browse all 75885

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>