Custom Fonts in Xamarin.iOS


Since that time, developers have left their programs stick out by using different fonts.

Although adding fonts ought to be an extremely straightforward procedure, programmers often express confusion on how to get it done for Xamarin.iOS programs.

In this blog article, I explain how to add a custom font into a tag. This ought to provide you an comprehension of the procedure and assist you when you are stuck.

First, find yourself a font using a acceptable license. I utilize, a fantastic source for discovering awesome-looking fonts. It’s possible to quickly locate free fonts which you can use on your program free of chargenevertheless, should you locate a superior font you want, you might have the ability to let it. It is possible to download a backup yourself should you would like to follow together. While hunting for appropriate fonts, it is well worth mentioning that iOS simply supports TTF and OTF. This should not be an issue since most fonts accessible on the web come in both of these formats.

Add The FontĀ 
You need to add the font for your job by either dragging and dropping into a folder or right clicking and choosing ‘Insert current file.’ In this case, I’ve added the ribbon into the Resources folder. It’s possible, of course, include the ribbon to any folder–such as the main directory in the event that you so choose.

When you’ve added the ribbon, you need to then right click it and pick the ‘Properties’ menu choice. If you neglect to do that you’ll find a null exception error when attempting to mention the font at runtime. This will lead to your Program to crash.

Highlighted land for clarity

The next step is to inform iOS wherever your customized font is saved. IOS will load those fonts in startup, so it is worth it to use custom fonts sparingly–it may slow the startup period of your Program.

To inform iOS you’re using custom fonts, then you need to start the Info.plist file and then choose ‘Source’ in the bottom of the view.

When you’ve completed this, you then need to double click on ‘Insert new entrance’ and then choose the ‘Fonts offered by program’ option. It’s here that you enter the location of this ribbon so that iOS understands where to search when loading the fonts in startup. Since I’ve put the ribbon in Resources, I will only type ‘HollywoodHills.ttf’ because the value. When I’d put the ribbon in Resources/Fonts, then I’d place the value to ‘Fonts/HollywoodHills. ttf’.

Utilizing the Customized font
Let us create two tags, one using our customized font and another with the default option. I have included code below which will make and put them tags for you. Consider running the program to see how it seems. If you configured your job as I explained above, it must work without any difficulties.

//Get size of screen

var height = UIScreen.MainScreen.Bounds.Height;

var width = UIScreen.MainScreen.Bounds.Width;


var lab1 = new UILabel(new RectangleF(0,0, width, height /2));

lab1.Text = “This is some sample text”;

lab1.Font = UIFont.FromName(“HollywoodHills”, 20f);


var lab2 = new UILabel(new RectangleF(0,height /2, width, height /2));

lab2.Text = “This is some more sample text”;


When you operate your Program, you may now see that the top tag employs the customized font you downloaded in Dafont. It is as simple as that. If you’re experiencing problems, you need to double-check that you’ve chosen the ‘Always replicate’ build property to your font and that the route is right from the Info.plist.

I hope you like using custom fonts in Programs as far as I have.

Author : Hire Xamarin Developer | Xamarin Development Company

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>