I want to dynamically update the text of a label so that parts of the label are underlined. (highlighting what section of the text the narrator is reading).
On Xamarin.UWP and Xamarin.Android this works as expected. On iOS it does not.
problem 1: text is not underlined as expected
problem 2: middle text span receives different fontsize while this property is set on the label
problem 3: textdecorations and fontattributes declared in xaml are not adhered
problem 4: bold sections is not bold, only the section that is bold AND underlined is bold
<Label Text="problem 1: text is not underlined as expected" TextColor="Red"/>
<Label Text="problem 2: middle text span receives different fontsize while this property is set on the label" TextColor="Red"/>
<Label Text="problem 3: textdecorations and fontattributes declared in xaml are not adhered" TextColor="Red"/>
<Label Text="problem 4: bold sections is not bold, only the section that is bold AND underlined is bold." TextColor="Red"/>
This issue has been moved from a ticket on Developer Community.
I want to dynamically update the text of a label so that parts of the label are underlined. (highlighting what section of the text the narrator is reading).
On Xamarin.UWP and Xamarin.Android this works as expected. On iOS it does not.
problem 1: text is not underlined as expected problem 2: middle text span receives different fontsize while this property is set on the label problem 3: textdecorations and fontattributes declared in xaml are not adhered problem 4: bold sections is not bold, only the section that is bold AND underlined is bold
On this page a user stated a regression in behaviour is introduced by moving from 16.0 to 16.2. I have not tested if downgrading fixes the problem. https://stackoverflow.com/questions/72121135/span-label-underline-is-not-working-on-xamarin-ios/75878433#75878433
The following sample code that illustrates multiple problems with textdecorations:
View: <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="BB.App.ViewModels.TestView"
===== Code Behind:
g System.Text; using Xamarin.Forms; using Xamarin.Forms.Xaml;
namespace BB. App.ViewModels { [XamlCompilation(XamlCompilationOptions.Compile)] public partial class TestView : ContentPage { public TestView() { InitializeComponent(); Label1.FontSize = 33; Label1.TextColor = Color.Black; Label1.FontFamily = "arial";
//Label2.FontSize = 33; //Label2.TextColor = Color.Black; //Label2.FontFamily = "arial";
}
private void Button_Clicked_lbl1_default(object sender, System.EventArgs e) { var formattedString = new FormattedString(); formattedString.Spans.Add(new Span() { Text = "text1 ", FontAttributes = FontAttributes.None, TextDecorations = TextDecorations.None }); formattedString.Spans.Add(new Span() { Text = "bold=0 ", FontAttributes = FontAttributes.None, TextDecorations = TextDecorations.None }); formattedString.Spans.Add(new Span() { Text = "underlined=0 ", FontAttributes = FontAttributes.None, TextDecorations = TextDecorations.None }); formattedString.Spans.Add(new Span() { Text = "bold & underlined=0 ", FontAttributes = FontAttributes.None, TextDecorations = TextDecorations.None }); formattedString.Spans.Add(new Span() { Text = " text3", FontAttributes = FontAttributes.None, TextDecorations = TextDecorations.None });
Label1.FormattedText = formattedString; }
private void lbl1_underline_center(object sender, System.EventArgs e) { var formattedString = new FormattedString(); formattedString.Spans.Add(new Span() { Text = "text1 ", FontAttributes = FontAttributes.None, TextDecorations = TextDecorations.None }); formattedString.Spans.Add(new Span() { Text = "bold=1 ", FontAttributes = FontAttributes.None, TextDecorations = TextDecorations.None }); formattedString.Spans.Add(new Span() { Text = "underlined=1 ", FontAttributes = FontAttributes.None, TextDecorations = TextDecorations.Underline }); formattedString.Spans.Add(new Span() { Text = "bold & underlined=1 ", FontAttributes = FontAttributes.Bold, TextDecorations = TextDecorations.Underline }); formattedString.Spans.Add(new Span() { Text = " text3", FontAttributes = FontAttributes.None, TextDecorations = TextDecorations.None });
Label1.FormattedText = formattedString; }
private void Button_Clicked_lbl2_default(object sender, System.EventArgs e) { var formattedString = new FormattedString(); formattedString.Spans.Add(new Span() { Text = "text1 ", FontAttributes = FontAttributes.None, TextDecorations = TextDecorations.None }); formattedString.Spans.Add(new Span() { Text = "bold=0 ", FontAttributes = FontAttributes.None, TextDecorations = TextDecorations.None }); formattedString.Spans.Add(new Span() { Text = "underlined=0 ", FontAttributes = FontAttributes.None, TextDecorations = TextDecorations.None }); formattedString.Spans.Add(new Span() { Text = "bold & underlined=0 ", FontAttributes = FontAttributes.None, TextDecorations = TextDecorations.None }); formattedString.Spans.Add(new Span() { Text = " text3", FontAttributes = FontAttributes.None, TextDecorations = TextDecorations.None });
Label2.FormattedText = formattedString; }
private void Button_Clicked_lbl2_underline_center(object sender, System.EventArgs e) { var formattedString = new FormattedString(); formattedString.Spans.Add(new Span() { Text = "text1 ", FontAttributes = FontAttributes.None, TextDecorations = TextDecorations.None }); formattedString.Spans.Add(new Span() { Text = "bold=1 ", FontAttributes = FontAttributes.None, TextDecorations = TextDecorations.None }); formattedString.Spans.Add(new Span() { Text = "underlined=1 ", FontAttributes = FontAttributes.None, TextDecorations = TextDecorations.Underline }); formattedString.Spans.Add(new Span() { Text = "bold & underlined=1 ", FontAttributes = FontAttributes.Bold, TextDecorations = TextDecorations.Underline }); formattedString.Spans.Add(new Span() { Text = " text3", FontAttributes = FontAttributes.None, TextDecorations = TextDecorations.None });
Label2.FormattedText = formattedString; }
private void Button_Clicked_lbl3_default(object sender, System.EventArgs e) { var formattedString = new FormattedString(); formattedString.Spans.Add(new Span() { Text = "text1 ", FontAttributes = FontAttributes.None, TextDecorations = TextDecorations.None, FontSize = 33 }); formattedString.Spans.Add(new Span() { Text = "bold=0 ", FontAttributes = FontAttributes.None, TextDecorations = TextDecorations.None, FontSize = 33 }); formattedString.Spans.Add(new Span() { Text = "underlined=0 ", FontAttributes = FontAttributes.None, TextDecorations = TextDecorations.None, FontSize = 33 }); formattedString.Spans.Add(new Span() { Text = "bold & underlined=0 ", FontAttributes = FontAttributes.None, TextDecorations = TextDecorations.None, FontSize = 33 }); formattedString.Spans.Add(new Span() { Text = " text3", FontAttributes = FontAttributes.None, TextDecorations = TextDecorations.None, FontSize = 33 });
Label3.FormattedText = formattedString; }
private void Button_Clicked_lbl3_underline_center(object sender, System.EventArgs e) { var formattedString = new FormattedString(); formattedString.Spans.Add(new Span() { Text = "text1 ", FontAttributes = FontAttributes.None, TextDecorations = TextDecorations.None, FontSize = 33 }); formattedString.Spans.Add(new Span() { Text = "bold=1 ", FontAttributes = FontAttributes.None, TextDecorations = TextDecorations.None, FontSize = 33 }); formattedString.Spans.Add(new Span() { Text = "underlined=1 ", FontAttributes = FontAttributes.None, TextDecorations = TextDecorations.Underline, FontSize = 33 }); formattedString.Spans.Add(new Span() { Text = "bold & underlined=1 ", FontAttributes = FontAttributes.Bold, TextDecorations = TextDecorations.Underline, FontSize = 33 }); formattedString.Spans.Add(new Span() { Text = " text3", FontAttributes = FontAttributes.None, TextDecorations = TextDecorations.None, FontSize = 33 });
Label3.FormattedText = formattedString; } } }
Original Comments
Feedback Bot on 5/16/2023, 08:16 PM:
(private comment, text removed)
Original Solutions
(no solutions)