Version

Override Default Font With Custom Font

Purpose

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.

Adding custom font to Android Project

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

xamarin override default font droid.png

Overriding default font in Android Project

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);

Adding custom font to iOS Project

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

xamarin override default font ios.png

Overriding default font in iOS Project

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);

Related Content

The following topics provide additional information related to this topic:

Topic Purpose

This topic describes how to set title and subtitle of XamCategoryChart control.

This topic describes how to set axis title of XamCategoryChart control.

This topic describes how to configure title and subtitle of XamDataChart control.

This topic describes how to configure axis title of XamDataChart control.