Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Responsive Font Size in Xamarin Forms

How can we make responsive font size in Xamarin forms like this in bootstrap?
If it is a smaller device, show small font,
if it is a larger device, then show large font size.

Is there any NuGet package or work source for that?

like image 448
Sabai Phoo Avatar asked Mar 24 '26 14:03

Sabai Phoo


2 Answers

You don't need any package for this. The functionality is built-in deep into Xamarin.Forms.

According to the Xamarin's documentation for the Font sizes:

The size value is measured in device-independent units. For more information, see Units of measurement

If you open the Units of measurement link, you will see that:

Xamarin.Forms uses a platform-independent unit of measurement that normalizes units across devices and platforms. There are 160 units per inch, or 64 units per centimeter, in Xamarin.Forms.

Also, if you look through the already predefined Named font sizes, you will see that there are some differences for each built-in size. This is exactly what is happening under the hood - Xamarin is "scaling" the font size accordingly, taking into account the device's dimensions.

like image 153
Mihail Duchev Avatar answered Mar 27 '26 11:03

Mihail Duchev


You don't need any NuGet package for this. If you want to set different sizes for phones and tabs you can do this.

<Label Text = "Hello"
FontSize = "{OnIdiom Phone = 20 Tablet = 72}" />

Xamarin scales the font size as the unit is device-independent.

like image 34
George Isaac Avatar answered Mar 27 '26 10:03

George Isaac