I'm using xamarin.forms to do an app and I perceived that to use the same size to letter to ios devices is not working: on 7 plus it works well, but on iphone 5 it's a Big letter for the size of the screen... Do someone know a way to do letter with scallable size, or change the size for a specific device or type of screen size? Thank you very much.
By using my markup, we are able to define different values for different screen sizes without the need to have a bunch of styling tags (or having as little as possible). It works not only for Labels but also for any kind of Xamarin forms UI elements like Grid, Image, Entry, Frame, Picker, and so forth.
You can refer following samples:
Estimate font-size for visual consistency - (docs | github)
// Resolution in device-independent units per inch.
double resolution = 160;
// Do some numeric point sizes.
int[] ptSizes = { 4, 6, 8, 10, 12 };
// Select numeric point size you need from ptSize[] array
double ptSize = 4;
// this is your new visually consistent font-size.
var fontSize = resolution * ptSize / 72;
Fitting text to available size - (docs | github)
double lineHeight = Device.OnPlatform(1.2, 1.2, 1.3);//TODO: Change this to Device.RuntimePlatform
double charWidth = 0.5;
int charCount = text.Length;
var view = this.Parent;
// Because:
// lineCount = view.Height / (lineHeight * fontSize)
// charsPerLine = view.Width / (charWidth * fontSize)
// charCount = lineCount * charsPerLine
// Hence, solving for fontSize:
int fontSize = (int)Math.Sqrt(view.Width * view.Height /
(charCount * lineHeight * charWidth));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With