FontAwesome Pro和xamarin.ios只能激活一种字体

所以我一直在寻找答案。

我无法在FontAwesome Pro中获得所有3种字体,以便与我的xamarin native(iOS)一起工作。

我确实用过

UIFont.FromName(fontName, size); 

但是“fontName”需要是Font的“family”名称,这是FontAwesome的一个问题,因为专业版中的所有版本都具有相同的PostScript名称。 它不是文件名,它是字体的家族属性。 因此,当我使用(在Mac上)Fontbook时,我可以看到fontawesome pro的所有三个版本(Regular,Light和Solid)都有相同的系列名称,即“Font Awesome 5 Pro”。

所以这意味着我只能使用应用程序中的三种字体之一。

我一直在寻找改变格式的解决方案,但我似乎无法找到任何方法。 但是,如果我可以设置我想要字体的格式,那么我想将’Light’,’Regular’或’Solid’定义为字体格式…

下载来自Fontbook的截图(抱歉,这是丹麦语)

在此处输入图像描述

这些字体还定义了Postscript系列名称,您可以使用它来代替主系列名称。

我没有专业版许可证,但免费的v5显示:

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

所以你可以:

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

仅供参考:要显示这些名称,请使用以下命令:

 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); } } 

在Xamarin.Forms中使用Font Awesome 5 Pro

使用它如下…(感谢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

     

在此处输入图像描述