2016-09-04 2 views
0

La police pour l'une de nos applications en ourdou est "Jameel Noori Nastaleeq Kasheeda". Nous sommes censés afficher du contenu (sur UILabel) après avoir converti son texte HTML en NSString.Conversion du texte HTML en NSString pour le contenu en utilisant la police Nastaleeq Urdu

Pour la conversion HTML au NSString, nous avons mis en œuvre les fonctions suivantes,

-(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]; 
} 

Ensuite, nous mettons propriété UILabel attributedText pour obtenir correctement formaté NSString basé sur le texte HTML.

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

Cette mise en œuvre fonctionne selon l'attente de polices par défaut iOS comme Arial ou Helvetica mais le texte est chevauchement lorsque nous polices appliqué ourdou personnalisée à savoir Nastaleeq. Toute aide à cet égard serait grandement appréciée.

enter image description here

Répondre

0

Vous pouvez implémenter WebView pour charger votre html string comme,

NSString* htmlString = @"your html string here"; 
    [webView loadHTMLString:htmlString baseURL: nil]; //webView is `UIWebView` object