我正在尝试为我的系统设置字体并在我的应用程序中使用它它适用于 android 但不适用于 IOS - 首先我在IOS项目的资源中添加了.ttf文件
然后将此字体添加到 Entitlements.plist
对于 Android,我添加到 Assets 文件夹
然后在主应用程序中的 App 文件我在字典资源中添加了这段代码
<Style x:Key="LableStyle" TargetType="Label" >
<Setter Property="Label.FontFamily">
<Setter.Value>
<OnPlatform x:TypeArguments="x:String">
<OnPlatform.Android>
DroidSansArabic.ttf#DroidSansArabic
</OnPlatform.Android>
<OnPlatform.iOS>
DroidSansArabic
</OnPlatform.iOS>
</OnPlatform>
</Setter.Value>
</Setter>
</Style>
对于标签,我添加了这样的样式
<Label HorizontalOptions="StartAndExpand"
Margin="20,5,0,0"
x:Name="lblForgotPassword"
Text="Forgot Password"
Style="{StaticResource LableStyle}">
</Label>
但它在 Android 上运行良好,但在 IOS 上却无法运行,为什么?
最佳答案
我假设您的字体系列名称在 iOS 上不正确。 macOS/iOS 字体名称不是没有扩展名的文件名,名称是在 ttf
本身中定义的。
我的 macOS 上的 DroidSansArabic.ttf
和我在 iOS 上使用的那个使用了 B Tabassom
的姓氏
所以它在表单中的用法是:
label.FontFamily = Device.OnPlatform(
iOS: "B Tabassom",
Android: "DroidSansArabic.ttf#DroidSansArabic",
WinPhone: null
);
由于周围有许多 DroidSansArabic.ttf,请通过在 macOS 的字体簿中打开 ttf
并查看标题栏来验证您的字体系列名称:
如果您的 macOS 已经安装了它,请查看名称列:
更新:您还在错误的 .plist
中输入了 UIAppFonts
键,它进入了 Info.plist
:
<key>UIAppFonts</key>
<array>
<string>DroidSansArabic.ttf</string>
</array>
</dict>
关于xamarin - 我需要从 .ttf 文件设置字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45768488/