Fontawesome Pro and Xamarin.iOS Only One Font Can Be Active

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

Those fonts also have Postscript family name defined you can use instead of the primary family name.

I do not have a pro license, but the free v5 show:

  * Font Awesome 5 Free
*-- FontAwesome5FreeRegular
*-- FontAwesome5FreeSolid

So you can:

var font = UIFont.FromName(@"FontAwesome5FreeSolid", 20);
var font = UIFont.FromName(@"FontAwesome5FreeRegular", 20);

FYI: To display those names, use the following:

foreach (var familyNames in UIFont.FamilyNames.OrderBy(c => c).ToList())
{
Console.WriteLine(" * " + familyNames);
foreach (var familyName in UIFont.FontNamesForFamilyName(familyNames).OrderBy(c => c).ToList())
{
Console.WriteLine(" *-- " + familyName);
}
}

How to use Font Awesome in Xamarin.iOS?

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.

Why doesn't Font Awesome display for iOS apps using Xamarin Forms?

On iOS, please use 'Real' name of font instead of the filename.

You can check this by rightclick on font file -> Properties -> Details -> Title on the windows. For example, I test a custom font file which the file name is Font Awesome 5 Free-Solid-900.otf. It does not work if set the value to the file name:

<OnPlatform x:TypeArguments="x:String" x:Key="FontAwesomeSolid">
...
<On Platform="iOS" Value="Font Awesome 5 Free-Solid-900" />
</OnPlatform>

Try getting the tilte of the custom font file and remove the 'space'.

Sample Image

Specify the value like below:

<OnPlatform x:TypeArguments="x:String" x:Key="FontAwesomeSolid">
<On Platform="iOS" Value="FontAwesome5Free-Solid" />
</OnPlatform>

Refer: Font Awesome not working in iOS

Cannot use custom font on Xamarin iOS

Open the font in the macOS Font Book app and review the actual name:

PostScript name BebasNeueRegular
Full name Bebas Neue Regular

So, in your code:

<On Platform="iOS" Value="Bebas Neue Regular" />

Re: https://stackoverflow.com/a/41567423/4984832

Re: https://stackoverflow.com/a/48191854/4984832

Re: https://stackoverflow.com/a/36942128/4984832

Xamarin Creating Custom Buttons with FontAwesome

In setter we set the value on existing property , so we should create a FontImageSource ,and assign it to ImageSource .

 public static Style BtnBack(ResourceDictionary resources)
{

FontImageSource source = new FontImageSource();
source.Glyph = "\uf3e5";
source.FontFamily = resources["FontAwesomeSolidOTF"];
source.Color = Color.FromHex("#fff");

return new Style(typeof(Button))
{
Setters = {
new Setter { Property = Button.ContentLayoutProperty, Value = new ButtonContentLayout(ButtonContentLayout.ImagePosition.Top, 5) },
new Setter { Property = Button.TextProperty, Value = "Back" },
new Setter { Property = Button.TextColorProperty, Value = "#565C5A" },
new Setter { Property = Button.HeightRequestProperty, Value = "80" },
new Setter { Property = Button.WidthRequestProperty, Value = "80" },
new Setter { Property = Button.PaddingProperty, Value = "0,15,0,15" },
new Setter { Property = Button.FontSizeProperty, Value = "14" },
new Setter { Property = Button.ImageSourceProperty, Value = source},
}
};
}

Swift FontAwesome 5 Pro icons don't show programmatically

Setting the attributed title cancels the titleLabel?.font. Set the font of the attributed string.



Related Topics



Leave a reply



Submit