本文介绍了iOS中的自定义阿拉伯字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我试图制作一个主要显示阿拉伯语言内容的iphone应用程序。我想使用自定义阿拉伯字体来显示该内容,而不是iPhone的默认阿拉伯字体。我使用了下面的代码: - (void)viewDidLoad { [super viewDidLoad]; [arabicLabel setFont:[UIFont fontWithName:@Simple Indust Shadedsize:20]]; arabicLabel.text = @السلامعليكم; } 其中arabicLabel是一个IBOutlet UILabel。我把标签放在应用程序资源中,并将其作为UIAppFont数组项添加到info.plist文件中。另外字体是 Unicode 。 当我在模拟器上运行这个代码时,标签显示默认的阿拉伯字体(不是我的自定义字体)。但是它的大小设置为20,如代码中所述! 我不明白我在这里做错了什么...我知道,在info.plist文件我必须添加扩展名(ttf)的字体文件名,我做到了。另外,我知道在前面的代码中,我必须把实际的字体名称不是文件名,所以我打开了我的Mac中的文件,并使用打开文件时出现的标题(简单的Indust阴影)。 我错过了什么吗?除了Unicode以外,是否还有对自定义字体的额外要求? 注意:我对自定义英文字体做了相同的过程,并且工作正常! > 解决方案 简短回答 这似乎是iOS中的一个错误。 p> 长答案 正如您所知道的,阿拉伯文文本需要在渲染前进行整形,将基本字母( Unicode:0600-06FF )转换为正确的对应上下文字母()。b $ b iOS会自动为阿拉伯文本进行预处理,但由于某些原因,它会忘记自定义字体,并在呈现连接的字母时使用系统默认字体。 $ b 解决方法 虽然如果你不能等,你可以使用此解决方法: 对文本进行预处理手动在呈现之前。这将允许跳过iOS预处理阶段导致这个问题,从而使用您的自定义字体呈现文本。 如果你想测试这个解决方案,只需复制下面的行和尝试它在您的项目: arabicLabel.text = @السلامعليكم; 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 = @"السلام عليكم";}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.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!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).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!... 解决方案 Short answerThis seems to be a bug in iOS.Long answerAs 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 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.So, it's a bug in iOS and you should wait for it to be solved.WorkaroundThough, 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中的自定义阿拉伯字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-23 09:13