Use Custom Fonts in Tizen .NET Apps
Juwon Ahn
Staff Engineer
Xamarin.Forms application
For general information regarding Xamarin.Forms fonts, see the following websites:
Install fonts and specify the font folder
You can add font files (.ttf
or .otf
files) to your res
directory and specify the global font path.
This code shows how to specify the fonts' global path.
- API Spec: ElmSharp.Utility.AppendGlobalFontPath
class Program : global::Xamarin.Forms.Platform.Tizen.FormsApplication
{
protected override void OnCreate()
{
base.OnCreate();
// To use a custom font, you need to add a global font path.
ElmSharp.Utility.AppendGlobalFontPath(this.DirectoryInfo.Resource);
LoadApplication(new App());
}
}
Use custom fonts
To use custom fonts, set the FontFamily
attribute.
The following example shows how to apply a custom font to a label.
----------
C#
----------
label.FontFamily = Device.RuntimePlatform == Device.iOS ? "Lobster-Regular" :
Device.RuntimePlatform == Device.Tizen ? "Lobster" :
Device.RuntimePlatform == Device.Android ? "Lobster-Regular.ttf#Lobster-Regular" : "Assets/Fonts/Lobster-Regular.ttf#Lobster",
-----------
XAML
-----------
<Label Text="Hello Forms with XAML">
<Label.FontFamily>
<OnPlatform x:TypeArguments="x:String">
<On Platform="Tizen" Value="Lobster" />
<On Platform="iOS" Value="MarkerFelt-Thin" />
<On Platform="Android" Value="Lobster-Regular.ttf#Lobster-Regular" />
<On Platform="UWP" Value="Assets/Fonts/Lobster-Regular.ttf#Lobster" />
</OnPlatform>
</Label.FontFamily>
</Label>
NUI application
As of Tizen 5.0, you can use custom fonts for NUI applications.
Install fonts and specify the font folder
You can add font files (.ttf
or .otf
files) to your res
directory and specify the global font path.
This code shows how to specify the font global path.
FontClient.Instance.AddCustomFontDirectory(this.DirectoryInfo.Resource);
Use custom fonts
Use custom fonts by setting the FontFamily
attribute.
The following example shows how to apply a custom font to a text label.
TextLabel text2 = new TextLabel("Apply a custom font to this label!");
text2.FontFamily = "Lobster";