简体   繁体   中英

How to use Font Awesome in Xamarin.iOS?

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

在此处输入图片说明

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

在此处输入图片说明

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.

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.

  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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM