我需要从.ttf文件设置字体 [英] I need To Set Font from .ttf File
问题描述
我正在尝试将字体设置为系统并在我的应用程序中使用它在android上工作正常,但不适用于IOS -首先,我在IOS项目的资源中添加了.ttf文件
I'm Trying to set font to my system and use it in my application it works fine for android but it does not apply for IOS - First I Added .ttf File to Resources in IOS Project
然后将该字体添加到Entitlements.plist
Then Added This Font to Entitlements.plist
对于Android,我已添加到资产文件夹
For Android, I Added to Assets Folder
然后在主应用程序中的应用程序文件中,我将此代码添加到字典资源中
Then App File in the Main Application I added this Code in dictionary Resources
<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>
对于标签,我添加了这样的样式
And for The Label I Added the Style like this
<Label HorizontalOptions="StartAndExpand"
Margin="20,5,0,0"
x:Name="lblForgotPassword"
Text="Forgot Password"
Style="{StaticResource LableStyle}">
</Label>
但是它在Android中可以正常运行,但在IOS中却不能运行,为什么?
But it works fine in Android but not working in IOS Why ?
推荐答案
我认为您的字体系列名称在iOS上不正确. macOS/iOS字体名称不是带扩展名的文件名,名称是在ttf
本身内定义的.
I would assume your font family name is incorrect on iOS. The macOS/iOS font names are not the filename sans extension, the names are defined within the ttf
itself.
我的macOS上的DroidSansArabic.ttf
和我在iOS上使用的DroidSansArabic.ttf
使用家族名称 B Tabassom
The DroidSansArabic.ttf
on my macOS and the one that I have used on iOS uses the family name of B Tabassom
因此它在Forms中的用法将是:
So the usage of it in Forms would be:
label.FontFamily = Device.OnPlatform(
iOS: "B Tabassom",
Android: "DroidSansArabic.ttf#DroidSansArabic",
WinPhone: null
);
由于周围有许多DroidSansArabic.ttf,请通过在macOS的字体簿"中打开ttf
并查看标题栏来验证您的字体系列名称是什么.
As there are a number of DroidSansArabic.ttf floating around, verify what your font family name is by opening the ttf
in macOS's Font Book and looking at the title bar:
如果您的macOS已经安装了它,请查看名称列:
If your macOS has it already installed, look in the name column:
更新:您还用UIAppFonts
键输入了错误的.plist
,它出现在Info.plist
中:
Update: You also the UIAppFonts
key in the wrong .plist
, it goes in the Info.plist
:
<key>UIAppFonts</key>
<array>
<string>DroidSansArabic.ttf</string>
</array>
</dict>
这篇关于我需要从.ttf文件设置字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!