Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Xamarin.Forms Label Font Bold

Tags:

In Xamarin.Forms I am using a Label and trying to set a Font.

The following code works:-

Label label1 = new Label(); label1.Font = Font.SystemFontOfSize(10); 

However trying to specify the Font Attributes such like:-

Label label1 = new Label(); label1.Font = Font.SystemFontOfSize(10, FontAttributes.Bold); 

is preventing the ContentPage from rendering with an exception.

There is a Font.BoldSystemFontOfSize(), which could be used, however this is meant to be deprecated, so I am trying to now use Font.SystemOfSize instead.

How is it done using this?

like image 746
Pete Avatar asked Aug 01 '14 17:08

Pete


People also ask

How do I make text bold in ASP labels?

Another option would be setting the Font. Bold property of the label to True. Assuming you can use several labels of course.


2 Answers

I guess I'm late for answering. But still I'd like to mention that, this can be done using XAML now. The following XAML will give the desired output.

<Label Text="Hello Label" FontSize="20" FontAttributes="Bold"/> 

You can refer to the following link to more about working with Fonts in Xamarin.Forms.

Working With Fonts in XForms

like image 63
Dash Avatar answered Oct 18 '22 16:10

Dash


Here's a piece of code that works in my project:

new Label {    Text = "text goes here",    Font = Font.SystemFontOfSize (NamedSize.Medium)               .WithAttributes (FontAttributes.Bold), } 

This allows you to not specify a certain font size and instead use the font size used by default for the label

like image 39
Sten Petrov Avatar answered Oct 18 '22 17:10

Sten Petrov