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?
Another option would be setting the Font. Bold property of the label to True. Assuming you can use several labels of course.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With