Change label size per screen size xamarin forms

Viewed 6526

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.

1 Answers

You can refer following samples:

  1. 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; 
    
  2. 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));
    
Related