【发布时间】:2020-01-08 18:40:36
【问题描述】:
我有一个 Xamarin Forms v4.2 解决方案,我想在其中使用一些 Font Awesome 5 图标。我已将 Font Awesome TTF 文件添加到我相信的正确位置,并根据平台正确设置了文件属性。但是当我尝试使用 FA 图标时,iOS 和 Android 会正确显示,而 UWP 会显示一个正方形来代替图标。我已经包含了 App.xaml、Page.xaml 和常量帮助程序文件的代码 sn-ps,以及 UWP 文件位置的图片和每个平台显示的图片。我相信这与 UWP 找不到字体文件有关,因为其他两个平台都可以正常工作。但我已经能够解决这个问题。
--- App.xaml ----
<OnPlatform x:Key="FontAwesome5FreeRegular" x:TypeArguments="x:String">
<On Platform="iOS" Value="FontAwesome5Free-Regular" />
<On Platform="Android" Value="fa-regular-free-400.ttf#Regular" />
<On Platform="UWP" Value="Assets/Fonts/fa-regular-free-400.ttf#Font Awesome 5 Free Regular" />
</OnPlatform>
--- Helper class for constant codes ---
public static class IconFontAwesome5FreeRegular
{
public const string Heart = "\uf004";
public const string Star = "\uf005";
}
--- Page.xaml ----
<StackLayout HeightRequest="100" Orientation="Vertical">
<Label
FontFamily="{StaticResource FontAwesome5FreeRegular}"
FontSize="44"
HorizontalOptions="CenterAndExpand"
Text="{x:Static fontawesome:IconFontAwesome5FreeRegular.Heart}"
TextColor="Red"/>
</StackLayout>
图片 1 - iOS 图 2 - UWP 图 3 - 安卓 图 4 - UWP 项目文件位置
【问题讨论】:
标签: xamarin.forms font-awesome-5