0

I'm new to Xamarin and was testing Xamarin features. Below is an excerpt from my toy application. As you can see, I tried in two ways to display some Chinese characters in italic.

<Label HorizontalOptions="Center" Grid.Row="2" Margin="20, 20, 20, 0"
       VerticalOptions="CenterAndExpand">
    <Label.FormattedText>
        <FormattedString>
            <Span Text="操舵室操舵室操舵室" FontSize="Medium" FontAttributes="Italic"
                  TextColor="#777777" />
        </FormattedString>
    </Label.FormattedText>
</Label>


<Label HorizontalOptions="Center" Grid.Row="3" Margin="20, 20, 20, 0" TextType="Html"
       VerticalOptions="CenterAndExpand">
    <![CDATA[
            <div style="font-size: 14px; color: #777777; font-style: italic;">操舵室操舵室操舵室<span style="color: #277DCA;">操舵室操舵室操舵室</span></div>
    ]]>

</Label>

However, both the simulator and the physical device display them as normal text (not italic). Below is a snapshot of the simulator.

Why this happens and how can I make these text italic?

Below is the package versions I use.

Just a learner
  • 26,690
  • 50
  • 155
  • 234

1 Answers1

0

I test your code, and the label text display Italic when using the first way, but there are some issue using second way to set Italic.

If you want to display html text in label , and set Italic, please using the following code:

  <Label

        HorizontalOptions="Center"
        TextType="Html"
        VerticalOptions="CenterAndExpand">
        <![CDATA[
This is <i style="font-size: 14px; color: #777777">操舵室操舵室操舵室</i> text.
]]>

    </Label>

And I don't have any issue when using the first way to set Italic , please check my screenshot:

enter image description here

This is my sample you can take a look:

https://github.com/CherryBu/LabelItalic-

Cherry Bu - MSFT
  • 10,160
  • 1
  • 10
  • 16