
This topic provides instructions how to override default font on all components of Ultimate UI for Xamarin product with a custom font, for example to display Japanese symbols in axis labels or titles of XamDataChart control.
This topic contains the following sections:
In .Droid project, add custom font .ttf file under Assets folder. Then set BuildAction to AndroidAsset in properties of the font file. The following figure shows how to configure .Droid project for custom Japanese font
Open MainActivity.cs file and add the following code to the OnCreate method:
In C#:
// loading Japanese font from Assets folder
var fontName = "irohamaru-mikami-Regular.ttf";
var fontPath = System.IO.Path.Combine(CacheDir.AbsolutePath, fontName);
using (var asset = Assets.Open(fontName))
{
using (var dest = System.IO.File.Open(fontPath, System.IO.FileMode.Create))
{
asset.CopyTo(dest);
}
}
// overriding default font with custom font that supports Japanese symbols
var font = SkiaSharp.SKTypeface.FromFile(fontPath);
Infragistics.Core.Controls.TypefaceManager.Instance.OverrideDefaultTypeface(font);
In .iOS project, add custom font .ttf file under Resources folder. Then set BuildAction to BundleResource in properties of the font file. The following figure shows how to configure .iOS project for custom Japanese font
Open AppDelegate.cs file and add the following code to the FinishedLaunching method:
In C#:
// loading Japanese font from Resources folder
var fontName = "irohamaru-mikami-Regular.ttf";
var fontPath = NSBundle.MainBundle.PathForResource(
System.IO.Path.GetFileNameWithoutExtension(fontName),
System.IO.Path.GetExtension(fontName));
// overriding default font with custom font that supports Japanese symbols
var font = SkiaSharp.SKTypeface.FromFile(fontPath);
Infragistics.Core.Controls.TypefaceManager.Instance.OverrideDefaultTypeface(font);
The following topics provide additional information related to this topic: