Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was facing the same problem until I read up about <code>NSAttributedStrings</code> (made available in iOS 6) on this tutorial <a href="http://weblog.invasivecode.com/post/31931916393/introduction-to-nsattributedstring-for-ios-6" rel="nofollow">here</a>. </p> <p>The following code will solve your issue:</p> <pre><code>NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:info.text attributes:@{ NSFontAttributeName : [UIFont fontWithName:@"Scheherazade" size:32], NSLigatureAttributeName: @2}]; cell.textLabel.attributedText = attributedString; </code></pre> <p>Out of curiosity, would I be correct to say that you opted to use <code>CoreText</code> because of difficulties in rendering embedded arabic fonts? I ventured the guess because I was attempting to use a similar method as you have done in your code when faced with that exact problem for a Quran app that I'm currently developing. If this so then I can confirm that using <code>NSAttributedString</code> also solves the problem. If you notice in the code above I've also set the <code>NSLigatureAttributeName</code> to <code>2</code> which according to the official Apple Class Reference Documentation means 'all ligatures'. Just note that this is something that I'm currently testing and I have yet to see the effects of this but I know that ligatures is a common problem in the rendering of some arabic fonts on certain platforms.</p> <p>While on the subject, another common problem you may be facing is the line-spacing of arabic text and the slight overlapping of multi-line text and I've found that <code>NSAttributedString</code> can also be a good solution when used together with <code>NSParagraphStyle</code> (Hooray again for <code>NSAttributedString</code>!). Simply modify the above code as below:</p> <pre><code>NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:info.text attributes:@{ NSFontAttributeName : [UIFont fontWithName:@"Scheherazade" size:32], NSLigatureAttributeName: @2}]; NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; [paragraphStyle setLineSpacing:20]; [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [info.text length])]; cell.textLabel.attributedText = attributedString; </code></pre> <p>Hope this helps you or anyone else out there!</p> <hr> <p>EDIT - Adding this helpful post on <a href="http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/" rel="nofollow">Common Mistakes With Adding Custom Fonts to Your iOS App</a> for reference as a "checklist" when adding custom fonts on iOS. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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