I have some text in grid. I need make half of it bold and other half should be normal. How can i make it? For example ;
gr.Children.Add(new Label { Text = $"Min. Adet : {data}", TextColor = Color.FromHex("#22223b"), FontSize = 16 }, 3, 3);
I need make bold = “Min. Adet : ” , and “{data}” that one should be normal. How can i make it ? Thanks for helps!!!
Answer
use Span and FormattedText
var layout = new StackLayout{ Padding = new Thickness (5, 10) }; ... var formattedString = new FormattedString (); formattedString.Spans.Add (new Span{ Text = "Red bold, ", ForegroundColor = Color.Red, FontAttributes = FontAttributes.Bold }); var span = new Span { Text = "default, " }; span.GestureRecognizers.Add(new TapGestureRecognizer { Command = new Command(async () => await DisplayAlert("Tapped", "This is a tapped Span.", "OK")) }); formattedString.Spans.Add(span); formattedString.Spans.Add (new Span { Text = "italic small.", FontAttributes = FontAttributes.Italic, FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)) }); layout.Children.Add (new Label { FormattedText = formattedString }); this.Content = layout;