2
votes

I am trying to use Font Awesome Icons in my Xamarin.iOS project.

In my Xamarin.Android project it was pretty simple:

  1. I downloaded the Font Awesome WebKit from here
  2. I copied the .ttf-Files of the fonts I want to use in my Assets folder

enter image description here

  1. I create a new Typeface for my TextView with the font and use the unicode of the icon

Code:

var myIcon = new TextView(Context);
var regularFont = Typeface.CreateFromAsset(Context.Assets, "fonts/fa-regular-400.ttf");
myIcon.SetTypeface(regularFont, TypefaceStyle.Normal);
myIcon.Text = "\uf007";

enter image description here

I can change TextColor, BackgroundColor, etc. like a normal text.

My problem is, I can't figure out, how to use Font Awesome in my Xamarin.iOS project. Most tutorials and How-Tos are directed to Xamarin.Forms. I tried to merge many of these approaches, but it failed.

The only approach I found is to draw the .svg-Files with SkiaSharp, but that is no option for my use case.

2
Place in your Resources folder, and ensure the build type is BundleResource . Check xamarinhelp.com/custom-fonts-xamarin-formsLucas Zhang
@LucasZhang-MSFT as the title of your helpthread says forms and I'm not working with .xml Files in Xamarion.iOS I have not considered this pageAiko West
@SushiHangover indeed, if I only load one fontawesome, it works :) I'll keep you updated, when I'm able to display all fontsAiko West

2 Answers

0
votes

SushiHangovers comment leads me to the solution for my problem.

FontAwesome Pro and xamarin.ios only one font can be active

It was not possible to use 3 Font Awesome fonts at the same time in the Designer, but it works when they are used during runtime via code.

0
votes
  1. Add .ttf files in your Xamarin iOS project (I have added it in resources)
  2. Now inside info.plist Add a new key “Fonts provided by application”
  3. Expand the array, and in string value add your fontname (eg: fa-solid-900.ttf) which you have added in your project
    Setup Done: Now Just wherever you want to add fontawesome icon just select font awesome as font family in storyboard but make sure to add text programmatically