iOS 中的自定义阿拉伯字体 [英] Custom Arabic font in iOS

查看:28
本文介绍了iOS 中的自定义阿拉伯字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个主要显示阿拉伯语内容的 iphone 应用程序.我想使用自定义阿拉伯字体来显示该内容,而不是 iPhone 默认的阿拉伯字体.我使用了以下代码:

I am trying to make an iphone application that displays mainly Arabic language content. I want to use a custom Arabic font for displaying that content, not the iPhone default Arabic font. I used the following code:

- (void)viewDidLoad {
    [super viewDidLoad];
    [arabicLabel setFont: [UIFont fontWithName: @"Simple Indust Shaded" size: 20]];
    arabicLabel.text = @"السلام عليكم";
}

其中 arabicLabel 是一个 IBOutlet UILabel.我将标签放在 App 资源中,并将其作为 UIAppFont 数组项添加到 info.plist 文件中.字体也是 Unicode.

where arabicLabel is an IBOutlet UILabel. I put the label in the App resources and add it to the info.plist file as UIAppFont array item. Also the font is Unicode.

当我在模拟器上运行这段代码时,标签显示了默认的阿拉伯字体(不是我的自定义字体);但是它按照代码中的说明将其大小设置为 20!

When I run this code on the simulator, the label displayed the default Arabic font (not my custom font); however it set its size to 20 as stated in the code!

我不明白我在这里做错了什么...我知道在 info.plist 文件中我必须添加带有扩展名 (ttf) 的字体文件名,我做到了.另外,我知道在之前的代码中我必须输入实际的字体名称而不是文件名,所以我在我的 Mac 中打开了文件并使用了打开文件时出现的标题(简单工业阴影).

I don't understand what I did wrong here... I know that in the info.plist file I must add the font file name with extension (ttf), and I did that. Also, I know that in the previous code I had to put the actual font name not file name, so I opened the file in my Mac and used the title that appeared when the file is opened (Simple Indust Shaded).

我错过了什么吗?除了 Unicode 之外,对自定义字体是否还有其他要求?

Am I missing something? Are there any extra requirements for custom fonts other than being Unicode?

注意:我对自定义英文字体做了同样的过程,它奏效了!...

NB: I did the same procedure for custom English font, and it worked!...

推荐答案

简短回答

这似乎是 iOS 中的一个错误.

Short answer

This seems to be a bug in iOS.

您可能知道,阿拉伯文本需要在呈现之前进行整形,这意味着转换基本字母 (Unicode:0600-06FF) 到相应的上下文字母(Unicode:FE70-FEFF).

As you may know, the arabic text needs to be shaped before it can be rendered, that means converting the basic letters (Unicode:0600-06FF) to their proper corresponding contextual letters (Unicode:FE70-FEFF).

iOS 会自动对阿拉伯文本进行预处理,但出于某种原因,它忘记了自定义字体,而在呈现连接的字母时仅使用系统默认字体.

iOS does this preprocessing automatically for arabic text, but for some reason, it forgets about the custom font and just uses system default font when it renders the connected letters.

所以,这是 iOS 中的一个错误,你应该等待它被解决.

So, it's a bug in iOS and you should wait for it to be solved.

不过,如果您迫不及待,可以使用以下解决方法:手动进行文本预处理 在渲染之前.这将允许跳过导致此问题的 iOS 预处理阶段,从而使用您的自定义字体呈现文本.

Though, if you can't wait, you can use this workaround: Do the preprocessing of the text manually before rendering it. This will allow skipping iOS preprocessing phase which causes this issue and thus rendering the text using your custom font.

如果您想测试此解决方案,只需复制以下行并在您的项目中尝试:

If you want to test this solution, just copy this following line and try it in your project:

arabicLabel.text = @"ﺍﻟﺴﻼﻡ ﻋﻠﻴﻜﻢ";

这篇关于iOS 中的自定义阿拉伯字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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