【发布时间】:2020-10-09 21:59:14
【问题描述】:
我在使用 Xamarin Forms 4.8 自定义字体时遇到问题。
我已按照信中的指南进行操作,即:
-将我的字体文件(.ttf 或 .otf)加载到我的共享目录中并将它们标记为嵌入式资源。
-在我的命名空间之外添加了 ExportFont。
当我在任何地方引用该字体时,它只会构建标准字体。这是一段sn-p代码:
using System;
using System.Collections.Generic;
using Xamarin.Forms;
using Newtonsoft.Json.Linq;
using System.IO;
using System.Reflection;
[assembly: ExportFont("Stencil.ttf")]
[assembly: ExportFont("GreatVibes.otf")]
[assembly: ExportFont("Lobster-Regular.ttf", Alias= "MyFont")]
namespace BAAaM
{
public partial class MainPage : ContentPage
{
public MainPage()
{
Grid topgrid = new Grid();
topgrid.Children.Add(new Label { Text = "Test, please work", FontSize = 30, FontFamily = "Lobster-Regular" }, 0, 1);
this.Content = topgrid;
}
}
}
我已经尝试将字体放入我的 Android 目录中的 assets 下,但这也不起作用。作为内置标签功能的一部分,Xamarin 是否会覆盖我使用标准字体所做的任何事情?更改文本大小没有问题。
谢谢,
M
【问题讨论】: