首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Xamarin在UWP中形成字体图标不正确显示

Xamarin在UWP中形成字体图标不正确显示
EN

Stack Overflow用户
提问于 2019-09-05 20:33:21
回答 1查看 2.5K关注 0票数 1

我有一个Xamarin表单v4.2解决方案,我想使用一些字体Awese5图标。我已经添加了字体Awesome文件在正确的位置,我相信与文件属性正确设置的基础上的平台。但是当我尝试使用FA图标时,iOS和Android会正确显示,UWP会显示一个正方形来代替图标。我已经包含了App.xaml、Page.xaml和常量辅助文件的代码片段,以及UWP文件位置的图片和每个平台显示的图片。我相信这与UWP找不到字体文件有关,因为其他两个平台工作得很好。但我一直能够纠正这一问题。

代码语言:javascript
运行
复制
--- 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项目文件位置

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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样式

代码语言:javascript
运行
复制
 <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="&#xf004;"
        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://fontawesome.com/v4.7.0/cheatsheet/

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57812633

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档