0

Font for one of our Urdu based app is "Jameel Noori Nastaleeq Kasheeda". We are supposed to show content (on UILabel) after converting its HTML text to NSString.

For converting HTML to NSString, we have implemented following functions,

-(NSString *)styledHTMLwithHTML:(NSString *)HTML{
   NSString *style = @"<meta charset=\"UTF-8\"><style> body { font-family: 'Jameel-Noori-Nastaleeq'; font-size: 20px; } b {font-family: 'Jameel-Noori-Nastaleeq'; }</style>";
   return [NSString stringWithFormat:@"%@%@", style, HTML];
}

- (NSAttributedString *)attributedStringWithHTML:(NSString *)HTML {
    NSDictionary *options = @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType };
    return [[NSAttributedString alloc] initWithData:[HTML dataUsingEncoding:NSUTF16StringEncoding] options:options documentAttributes:NULL error:NULL];
}

Then we are setting UILabel's attributedTextproperty to get properly formatted NSString based on HTML text.

NSString *styledHtml = [self.novel.article styledHTMLwithHTML:self.novel.article];
NSAttributedString *attributedText = [self.novel.article attributedStringWithHTML:styledHtml];
self.articleView.articleContent.attributedText = attributedText;

This implementation is working as per expectation of default iOS fonts like Arial or Helvetica but text is overlapping when we applied custom Urdu font i.e. Nastaleeq. Any help in this regard would be highly appreciated.

enter image description here

ihammys
  • 812
  • 7
  • 15

1 Answers1

0

You can implement webview to load your html string like,

  NSString* htmlString = @"your html string here";
  [webView loadHTMLString:htmlString baseURL: nil]; //webView  is `UIWebView` object
Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75