Span Label underline is not working on Xamarin iOS

I'm using a Label with Spans, one of them is a link and I want to add an underline style, I'm using <Span Text="Link url" TextDecorations="Underline" /> but it is not working in iOS with "Xamarin.Forms" Version="5.0.0.2401".

I have tried to add an effect but all the properties needs to be set again (Styles, touch events, etc...).

<Label>
    <Label.FormattedText>
        <FormattedString>
            <Span Text="Text 1"/>
            <Span Text="Text 2"/>
            <Span Text="Click to open Link" TextDecorations="Underline">
                <Span.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding lINKCommand}"/>
                </Span.GestureRecognizers>
            </Span>
        </FormattedString>
    </Label.FormattedText>
</Label>

In some time Xamarin forms needs to fix it, meanwhile I want to apply a small temporal fix.

Upvotes: 3

Views: 1564

Answers (4)

YoungEddie
YoungEddie

Reputation: 425

Xamarin Span stopped to display text decorations when I have updated iOS SDK from 16.0 to 16.2. Xamarin.Forms version 5.0.0.2545 and 5.0.0.2578 does not fix this problem. My solution for that is to replace Span with simple Label, then text decorations works. Little extra work.

Upvotes: 0

Leonard Barbu
Leonard Barbu

Reputation: 71

The TextType.Html trick is working. I can see the underline, but it my case it brakes the TapGestureRecognizer command. So setting the Label on Html text type and after back to Text text type solves also this.

protected override void OnAppearing()
{
    base.OnAppearing();
    MyLabel.TextType = TextType.Html;
    MyLabel.TextType = TextType.Text;
}

Upvotes: 4

Marek Kuźniecow
Marek Kuźniecow

Reputation: 31

I have also discovered that it works when You set FontSize in Label at runtime.

Upvotes: 2

I discovered that it works when set TextType property to Html in the Label at runtime.

So I had to create a data trigger and use a data binding to set when all data is loaded.

<Label>
    <Label.Triggers>
        <DataTrigger TargetType="Label" Binding="{Binding IsBusy}" Value="false">
            <Setter Property="TextType" Value="Html" />
        </DataTrigger>
    </Label.Triggers>
    <Label.FormattedText>
        <FormattedString>
            <Span Text="Text 1"/>
            <Span Text="Text 2"/>
            <Span Text="Click to open Link" TextDecorations="Underline">
                <Span.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding lINKCommand}"/>
                </Span.GestureRecognizers>
            </Span>
        </FormattedString>
    </Label.FormattedText>
</Label>

Upvotes: 4

Related Questions