html – iOS中包含自定义字体的阿拉伯文字

html – iOS中包含自定义字体的阿拉伯文字,第1张

概述我正在开发一个应用程序,需要使用自定义阿拉伯字体显示阿拉伯语文本.问题是,我没有运气使用自定义阿拉伯字体显示阿拉伯语文本.我试图在UILabel,UITextField,UITextView,UIWebView,FontLabel(由Zynga)和使用CoreText显示文本. 您可以在此处找到示例项目: Sample application using UILabel, UITextField 我正在开发一个应用程序,需要使用自定义阿拉伯语字体显示阿拉伯语文本.问题是,我没有运气使用自定义阿拉伯字体显示阿拉伯语文本.我试图在UILabel,UITextFIEld,UITextVIEw,UIWebVIEw,FontLabel(由Zynga)和使用CoreText显示文本.

您可以在此处找到示例项目:

Sample application using UILabel,UITextView and CoreText

Sample application using UIWebView (HTML)

Sample application using UIWebVIEw (HTML): You’ll have to install the
Fonts in the sample project. You can then compare the results and see
the problem by running the application in the simulator (or iPad),and
opening Sample.HTML file in the browser (Safari).

我在Apple的开发者论坛上发布了一些细节,但我总是发现stackoverflow比Apple的官方开发者论坛更加活跃.这是该帖子的链接:

Using custom arabic font in iOS

What am i doing wrong?

注意:字体正确加载到系统中,我可以成功将自定义字体应用于常规(英语)文本.

附: stackoverflow上有几篇帖子谈论这个主题,但没有一个有很大的帮助,所以我发布了一个新的问题.

解决方法 更新:

从iOS 7开始,您不需要使用Core Text来呈现自定义的阿拉伯字体.您可以将UILabel和/或UITextVIEw与NSAttributedString一起使用.结果与使用Core-Text的结果相同.但是,根据您的要求,使用Core Text仍然是更好的选择.

更新:

我已将此报告为Apple的错误,但我不确定他们何时会添加对阿拉伯字体的支持.目前,没有简单的方法可以做到这一点.我最终使用默认的系统字体,这不是很好.

原始信息

我确实设法构建了一个使用自定义阿拉伯字体的古兰经应用程序.我使用已知的阿拉伯字体与Core Text框架来获得所需的结果.通过检查应用程序商店中提供的应用程序Quran Presenter for iPad,您可以看到我最终得到的结果.

这里有一些示例代码可以帮助您:

- (CTFontRef)newCustomFontWithname:(Nsstring *)aFontname                            ofType:(Nsstring *)type                        attributes:(NSDictionary *)attributes {    Nsstring *FontPath = [[NSBundle mainBundle] pathForResource:aFontname ofType:type];    NSData *data = [[NSData alloc] initWithContentsOffile:FontPath];    CGDataProvIDerRef FontProvIDer = CGDataProvIDerCreateWithCFData((CFDataRef)data);    [data release];    CGFontRef cgFont = CGFontCreateWithDataProvIDer(FontProvIDer);    CGDataProvIDerRelease(FontProvIDer);    CTFontDescriptorRef FontDescriptor = CTFontDescriptorCreateWithAttributes((CFDictionaryRef)attributes);    CTFontRef Font = CTFontCreateWithGraphicsFont(cgFont,NulL,FontDescriptor);    CFRelease(FontDescriptor);    CGFontRelease(cgFont);    return Font;}- (CATextLayer *)customCATextLayer {    NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:                                [NSNumber numberWithfloat:24.f],(Nsstring *)kCTFontSizeAttribute,[NSNumber numberWithInt:1],(Nsstring *)kCTligatureAttributename,nil];    CTFontRef Font = [self newCustomFontWithname:@"PDMS_Saleem_QuranFont-signed"                                           ofType:@"ttf"                                       attributes:attributes];    CATextLayer *normalTextLayer = [[CATextLayer alloc] init];    normalTextLayer.Font = Font;    normalTextLayer.string = NSLocalizedString(@"Sample",nil);    normalTextLayer.wrapped = YES;    normalTextLayer.foregroundcolor = [[UIcolor blackcolor] CGcolor];    normalTextLayer.FontSize = 24.f;    normalTextLayer.alignmentMode = kCAAlignmentCenter;    normalTextLayer.frame = CGRectMake(0.f,10.f,320.f,32.f);    CFRelease(Font);    return [normalTextLayer autorelease];}- (voID)vIEwDIDLoad {    [super vIEwDIDLoad];    CATextLayer *normalTextLayer = [self customCATextLayer];    [self.customVIEw.layer addSublayer:normalTextLayer];}

请注意,我正在使用CATextLayer和CTFontRef.这种方法存在一些问题.
1.您将不得不忍受选定的“自定义阿拉伯字体”中的问题.
2.您必须使用使用字体支持的扩展字符的阿拉伯语文本.

HTH.

总结

以上是内存溢出为你收集整理的html – iOS中包含自定义字体的阿拉伯文字全部内容,希望文章能够帮你解决html – iOS中包含自定义字体的阿拉伯文字所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1106622.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存