【发布时间】:2017-07-22 03:35:25
【问题描述】:
使用 Xamarin Forms (2.3.1) 和 Prism (6.2) 开发适用于 iOS 和 Android 的应用程序,我们很难让自定义字体在 Android 上运行,但 iOS 一直很好。
我们关注the most recent documentation(即不使用自定义渲染),似乎已将其范围缩小到与 Prism 相关...
为了简化问题,我们制作了一个新的 Forms App,将 Xamarin demo 中的 Lobster-Regular.ttf 添加到 Android Assets 和 iOS Resources 并确保其属性分别为 AndroidAsset 和 BundleResource,然后在默认的 xaml 页面中添加:
<Label Text="Hello Forms with XAML">
<Label.FontFamily>
<OnPlatform x:TypeArguments="x:String">
<OnPlatform.iOS>MarkerFelt-Thin</OnPlatform.iOS>
<OnPlatform.Android>Lobster-Regular.ttf#Lobster-Regular</OnPlatform.Android>
<OnPlatform.WinPhone></OnPlatform.WinPhone>
</OnPlatform>
</Label.FontFamily>
</Label>
(这也是直接来自演示)
它适用于 iOS 和 Android。
如果我们创建一个新的 Prism Unity App,添加字体文件,检查属性(默认正确)并在 MainPage.xaml 中插入标签 iOS 将使用自定义字体,而 Android 将只使用标准字体。
有一个known issue with custom fonts in UWP and WP apps,但这似乎不相关。
所有测试均在 iOS 模拟器和 Android 模拟器上进行。
更新 根据 Dan S. 的评论,我上传了一个项目来展示一个最小的棱镜应用程序,该应用程序具有适用于 iOS 但不适用于 Android 的自定义字体:sample project
【问题讨论】:
-
您能否提供一个示例来说明该问题? Prism 不应该以某种方式对显示自定义字体等产生任何影响。
-
我已经上传了一个项目来演示它,是的,我同意 Prism 不应该产生影响,但正如我所说,我试图缩小范围,并且这些步骤适用于非 Prism 应用程序和Prism 应用程序 iOS 无法正常运行 Android ¯_(ツ)_/¯
标签: xamarin xamarin.forms prism