【问题标题】:Roboto Font not working in Xamarin iOSRoboto 字体在 Xamarin iOS 中不起作用
【发布时间】:2017-03-03 05:26:20
【问题描述】:

我尝试使用 this guide 在 Xamarin iOS 中使用自定义字体。我将字体添加到 Resources/Fonts 文件夹。然后将其添加到数组属性Fonts provided by application 下的info.plist 中。我将字体的属性更改为捆绑资源并始终复制。

现在,新添加的字体必须在 xamarin 设计器中显示。但是,Roboto-Regular.ttf 没有显示。但它对OpenSans-Regular.ttf 工作正常。

欢迎任何帮助!

【问题讨论】:

  • 我与 xamarin 设计器有类似的问题,我必须使用 xml 编辑器打开文件手动设置字体名称并重新加载 ui 设计器......让我抓狂

标签: ios xamarin.ios


【解决方案1】:

iOS 可能会以不同的字体名称注册字体。如果您的字体已成功注册(如您的步骤所示),您可以在 UIFonts.FontFamilyNames 数组中找到它,然后使用它。要查找所有已注册的字体,

foreach (var fontFamily in UIFont.FamilyNames)
{
    foreach (var font in UIFont.FontNamesForFamilyName(font))
    {
        System.Diagnostics.Debug.Console.WriteLine(item);
    }
    System.Diagnostics.Debug.Console.WriteLine("---");
}

如果您仍然看不到您的字体。尝试通过名称显式找到它,

foreach (var font in UIFont.FontNamesForFamilyName(friendlyFontName)) // can have space in font name.
{
    System.Diagnostics.Debug.Console.WriteLine(item);
}
System.Diagnostics.Debug.Console.WriteLine("---");

如果您在那里找到了您的字体,这就是您需要在代码中用作字体名称的字体。

例子,

我最近使用了 Bbas Neue。文件名在哪里,

  • BebasNeue Regular.ttf
  • BebasNeue Bold.ttf
  • BebasNeue Thin.ttf

在 android 中,我使用了 BebasNeue Regular.ttf#BebasNeue Regular,它按预期工作。然而,在 iOS 中,字体名称如下,

  • BebasNeueRegular
  • BebasNeueBold
  • BebasNeue-Thin

如您所见,不是任何模式。所以在寻找字体系列 Bebas Neue(带空格)后,我找到了正确的名称,并且能够在 iOS 上使用该字体。

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-24
    • 2020-03-24
    • 2016-10-24
    • 1970-01-01
    • 2021-11-17
    • 2020-10-20
    • 1970-01-01
    • 2022-10-17
    相关资源
    最近更新 更多