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);
}
}
To use Font Awesome 5 Pro in Xamarin.Forms
Use it like below... (Thanks to the helpful code of SushiHangover)
- Font Awesome 5 Brands *-- FontAwesome5BrandsRegular
- Font Awesome 5 Pro *-- FontAwesome5ProLight *-- FontAwesome5ProRegular *-- FontAwesome5ProSolid
App.Xaml.cs
Current.Resources = new ResourceDictionary();
// Font awesome
Current.Resources["FontawesomeSolid"] = Device.RuntimePlatform == Device.iOS ? "Font Awesome 5 Pro" : "fa-solid-900.ttf#Font Awesome 5 Pro";
Current.Resources["FontawesomeRegular"] = Device.RuntimePlatform == Device.iOS ? "FontAwesome5Regular" : "fa-regular-400.ttf#Font Awesome 5 Pro";
Current.Resources["FontawesomeLight"] = Device.RuntimePlatform == Device.iOS ? "FontAwesome5ProLight" : "fa-light-300.ttf#Font Awesome 5 Pro";
Current.Resources["FontawesomeBrands"] = Device.RuntimePlatform == Device.iOS ? "FontAwesome5ProBrands" : "fa-brands-400.ttf#fFont Awesome 5 Pro";
Current.Resources.Add("ShareIconLabel", new Style(typeof(Label))
{
Setters =
{
new Setter { Property = Label.TextColorProperty, Value = Color.White},
new Setter { Property = View.HorizontalOptionsProperty, Value = LayoutOptions.End},
new Setter { Property = View.VerticalOptionsProperty, Value = LayoutOptions.Center},
new Setter { Property = AbsoluteLayout.LayoutBoundsProperty, Value = new Rectangle (0.90, 0.5, 0.2, 1)},
new Setter { Property = AbsoluteLayout.LayoutFlagsProperty, Value = AbsoluteLayoutFlags.All},
new Setter { Property = Label.FontSizeProperty, Value = 30},
new Setter { Property = Label.FontFamilyProperty, Value = Current.Resources["FontawesomeLight"] },
new Setter { Property = Label.TextProperty, Value = "\uf1e0" } // Share Icon
}
});
MySharePage.Xaml
<AbsoluteLayout
AbsoluteLayout.LayoutBounds="0,1,1,0.07"
AbsoluteLayout.LayoutFlags="All"
BackgroundColor="{x:Static localColors:Constants.MyOrange} ">
<Label
Style="{StaticResource ShareIconLabel}">
<!--<Label.GestureRecognizers>
<TapGestureRecognizer
Tapped="OnSocialShareClicked" />
</Label.GestureRecognizers>-->
</Label>
</AbsoluteLayout>