我需要从 .ttf 文件设置字体 [英] I need To Set Font from .ttf File

查看:37
本文介绍了我需要从 .ttf 文件设置字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的系统设置字体并在我的应用程序中使用它它适用于 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,我添加到 Assets 文件夹

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 上使用的那个使用了姓氏 B Tabassom

The DroidSansArabic.ttf on my macOS and the one that I have used on iOS uses the family name of B Tabassom

所以它在表单中的用法是:

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屋!

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