Forum Xamarin Xamarin.Forms

What are the measure units for FontSize and how to make it related to font height?

AlexKeyAlexKey USMember ✭✭

My main target to to set such FontSize on a Label that in the result the Label height would become the desired value. For example, I want the Label to be 50 Xamarin Forms units high what value should I use for the FontSize in this case? How to calculated FontSize from the font height?

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    How to calculated FontSize from the font height?

    There is no method to measure units for FontSize depends on the font height .

    Actually, Xamarin.Forms defines fields in the NamedSize enumeration that represent specific font sizes , the size values are measured in device-independent units , maybe you can try this .

  • JohnHardmanJohnHardman GBUniversity admin

    @AlexKey said:
    My main target to to set such FontSize on a Label that in the result the Label height would become the desired value. For example, I want the Label to be 50 Xamarin Forms units high what value should I use for the FontSize in this case? How to calculated FontSize from the font height?

    For techniques around sizing and fonts, see https://docs.microsoft.com/en-us/xamarin/xamarin-forms/creating-mobile-apps-xamarin-forms/summaries/chapter05

  • AlexKeyAlexKey USMember ✭✭

    What I ended up doing, not sure if it will work cross-platform, I tested it only on Android, I added Label tags to a page and specified font sizes with a step of 10 from 10 to 100. Then I got the Height property from Label. In the result, an approximate ratio Label.Height to Label.FontSize was 0.75. Then I used that factor to calculate the FontSize when I know that I need particular height to be occupied by the Label. So far it worked as I wanted. Still not sure what will happen in iOS for example but I hope the ratio will maintain the same, the absolution numbers might be different.

Sign In or Register to comment.