Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Update:</strong></p> <p>As of iOS 7, you don't really need to use Core Text to render custom arabic font. You can use <code>UILabel</code> and/or <code>UITextView</code> with <code>NSAttributedString</code>. The results are the same as you get using Core-Text. However, depending on your requirements, using Core Text can still be a better option.</p> <p><strong>Update:</strong></p> <p>I've reported this as a bug to Apple, but i'm not sure when they'll add support for Arabic fonts. Currently, there's no easy way to do it. I ended up using the default system font, which is not very good.</p> <p><strong>Original Message</strong></p> <p>I did managed to build a Quran application that uses custom arabic font. I used known arabic font(s) with <code>Core Text</code> framework to get the desired results. You can see the results I got in the end by checking the application <a href="http://itunes.apple.com/my/app/quran-presenter/id501612863?mt=8" rel="nofollow">Quran Presenter for iPad</a>, which is available on the App Store.</p> <p>Here's some sample code to help you out:</p> <pre><code>- (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, 0, 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]; } </code></pre> <p>Note that I'm using <code>CATextLayer</code> and <code>CTFontRef</code>. There are a few problems with this approach. 1. You'll have to live with the issues in the selected "custom arabic font". 2. You'll have to use the arabic text that uses the extended characters supported by the font.</p> <p>HTH.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload