关于我可以同时用于Android和iOS的字体的建议,这些字体看起来与每种字体的系统默认字体相似 [英] Suggestions on a font I can use for both Android and iOS that looks similar to the system default fonts of each

查看:944
本文介绍了关于我可以同时用于Android和iOS的字体的建议,这些字体看起来与每种字体的系统默认字体相似的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android和iOs Forms应用程序,当前使用每个操作系统的默认字体.我希望两个应用程序看起来都尽可能相似.

I have an Android and iOs Forms application that currently uses the default fonts of each OS. I would like both applications to look as similar as possible.

有没有可以用于此目的的字体包,以及如何实现此功能.我意识到选择字体是很多人可能会有不同的看法,但是一些起步建议和任何建议将不胜感激.

Are there any font packages that I could use for this and how could I implement this functionality. I realize that selection of fonts is something that many people could have different opinions but some started suggestions and any advice would be much appreciated.

推荐答案

我认为,您可以为此使用一些常见的FontFamily. 从本教程开始,您必须添加所需的字体(.ttf格式) 对于每个平台,您需要执行以下操作: iOS:

As I think, you can use some common FontFamily for this. As from this tutorial, you have to add a font you want (.ttf format) and for each platform you need to do the following things: iOS:

在您喜欢的文本编辑器中和本节中打开info.plist.

Open your info.plist in your favorite text editor and at this section.

<key>UIAppFonts</key>
<array>
<string>Fonts/Lato-Regular.ttf</string>
<string>Fonts/Stackyard.ttf</string>
<string>Fonts/ComicSaaaaaans.ttf</string>
</array>

从那里,您可以使用iOS Appearance API将字体应用于所需的任何字体.在我的情况下,这是导航栏,结果是这样:

From there you can use the iOS Appearance API to apply your font to whatever you want. In my case this was the navigation bar, which resulted in this:

UINavigationBar.Appearance.SetTitleTextAttributes(new UITextAttributes
{
   TextColor = UIColor.White,
   Font = UIFont.FromName("Stackyard PERSONAL USE", 32)
});

对于Android:

现在我们需要做的是为其中的控件创建一个CustomRenderer 我们要显示我们的字体! 一个明显的选择是Label控件.当我们定义一个渲染器 此代码覆盖ElementChanged,我们可以使用StyleId,例如 您已经在上面看到了,可以从我们的共享中指定要使用的字体 代码!

Now what we need to do is create a CustomRenderer for the controls in which we want to show our fonts! A obvious choice is the Label control. When we define a renderer with this code overriding the ElementChanged we can use the StyleId, like you’ve seen above, to specify which font to use right from our shared code!

protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
   base.OnElementChanged(e);

   if (!string.IsNullOrEmpty(e.NewElement?.StyleId))
   {
      var font = Typeface.CreateFromAsset(Forms.Context.ApplicationContext.Assets, e.NewElement.StyleId + ".ttf");

       Control.Typeface = font;
    }
}

希望这会有所帮助! :)

Hope this helps! :)

这篇关于关于我可以同时用于Android和iOS的字体的建议,这些字体看起来与每种字体的系统默认字体相似的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆