Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change label size per screen size xamarin forms

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.

like image 510
Joyce de Lanna Avatar asked Sep 21 '17 16:09

Joyce de Lanna


People also ask

How does Xamarin form handle different screen sizes?

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.


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));
    
like image 132
Sharada Gururaj Avatar answered Oct 12 '22 07:10

Sharada Gururaj