我有一个Xamarin表单v4.2解决方案,我想使用一些字体Awese5图标。我已经添加了字体Awesome文件在正确的位置,我相信与文件属性正确设置的基础上的平台。但是当我尝试使用FA图标时,iOS和Android会正确显示,UWP会显示一个正方形来代替图标。我已经包含了App.xaml、Page.xaml和常量辅助文件的代码片段,以及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- Android图像4- UWP项目文件位置
发布于 2019-09-06 03:14:49
我下载fa-正则-400.ttf,添加到Android,UWP中,它在我身边运行的很好。
在Android资产中添加fa-Reg-400.ttf,将属性更改为AndroidAssets,并在UWP资产中添加fa-Reg-400.ttf。
在FontFamily中创建App.Xaml样式
<Application.Resources>
<ResourceDictionary>
<Style x:Key="FontAwesome5FreeRegular" TargetType="Label">
<Setter Property="FontFamily">
<Setter.Value>
<OnPlatform x:TypeArguments="x:String">
<On Platform="iOS" Value="Font Awesome 5 Free" />
<On Platform="Android" Value="fa-regular-400.ttf#Font Awesome 5 Free Regular" />
<On Platform="UWP" Value="Assets/fa-regular-400.ttf#Font Awesome 5 Free" />
</OnPlatform>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
</Application.Resources>
<Label
BackgroundColor="White"
FontSize="36"
HeightRequest="100"
Style="{StaticResource FontAwesome5FreeRegular}"
Text=""
TextColor="Black">
</Label>
在标签样式中使用FontAwesome5FreeRegular样式,我在Android和uwp中得到相同的样式。
您还可以查看下面的文章以获得帮助。
https://www.wintellect.com/using-fontawesome5-xamarin-forms/
https://www.msctek.com/font-awesome-xamarin-forms-xaml/
关于图标unicode,请参阅:
https://stackoverflow.com/questions/57812633
复制相似问题