Skip to content

Instantly share code, notes, and snippets.

@pm64

pm64/PaintUtils.cs Secret

Created Aug 7, 2020
Embed
What would you like to do?
public class PaintUtils : Pos.PaintUtils.ICalculateTextWidth
{
public double CalculateWidth(string text)
{
Rect bounds = new Rect();
var textView = new TextView(Forms.Context);
textView.Paint.GetTextBounds(text, 0, text.Length, bounds);
var length = bounds.Width();
return length / Res.Resources.System.DisplayMetrics.ScaledDensity;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment