0
votes

I have a label in my app UI that takes HTML data. So I set TextType="Html" property for that label. In small-screen devices I need 16 and for big-screen devices I need 32 as it's font size. But no change in label font size because of the TextType="Html" property.

XAML Label Code

<Label
    x:Name="message_label"
    VerticalOptions="Start"
    VerticalTextAlignment="Center"
    TextType="Html"
    TextColor="Black"
    Margin="5"
    FontSize="Medium">
    <Label.FontFamily>
        <OnPlatform x:TypeArguments="x:String">
            <On Platform="iOS" Value="MouseMemoiresRegular" />
            <On Platform="Android" Value="MouseMemoiresRegular.ttf#MouseMemoiresRegular" />
            <On Platform="UWP" Value="Assets/Fonts/MouseMemoiresRegular.ttf#MouseMemoiresRegular" />
        </OnPlatform>
    </Label.FontFamily>
    <Label.FontSize>
        <OnIdiom x:TypeArguments="x:Double">
            <OnIdiom.Phone>16</OnIdiom.Phone>
            <OnIdiom.Tablet>32</OnIdiom.Tablet>
        </OnIdiom>
    </Label.FontSize>
</Label>

So how can I increase the font size in this case?

1

1 Answers

1
votes

If you want to put html in label, and want to increase the fontsize of label, I suggest you can use Xam.Plugin.HtmlLabel.

Firstly, you can install Xam.Plugin.HtmlLabel in your project,

Then render this in different platform.

iOS: AppDelegate.cs

HtmlLabelRenderer.Initialize();
global::Xamarin.Forms.Forms.Init();

Android: MainActivity.cs

HtmlLabelRenderer.Initialize();
global::Xamarin.Forms.Forms.Init(this, bundle);

UWP: App.xaml.csenter code here

var rendererAssemblies = new[] { typeof(HtmlLabelRenderer).GetTypeInfo().Assembly };
Xamarin.Forms.Forms.Init(e, rendererAssemblies);
HtmlLabelRenderer.Initialize();

than use the HtmlLable like this:

<htmllabel:HtmlLabel FontSize="12" Text="&lt;h1&gt;Hello World!&lt;/h1&gt;&lt;br/&gt;SecondLine" />

        <htmllabel:HtmlLabel FontSize="20" Text="&lt;h1&gt;Hello World!&lt;/h1&gt;&lt;br/&gt;SecondLine" />

You can change different fontsize in htmllabel.