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 attributedText
property 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.