Reputation: 1205
I'm trying to make part of text inside the label - bold. Here is a html code I'm using:
<style>body{line-height: 0;}</style><font face=\"Calibri\"><b>Get moving!</b> (and Sync to see your points.)</font>
But it's making all text bold. The same thing if HTML is using <b></b>
tags. It will make all text regular.
Seems that it's checking only beginning.
Can anyone help me with that?
I'm using NSAtributedString
for showing HTML text. Want to admit that it's working fine in HTML online editors.
Upvotes: 2
Views: 1771
Reputation: 277
NSString *description = @"<style>body{line-height: 0;}</style><font face=\"Calibri\"><b>Get moving!</b> (and Sync to see your points.)</font>";
self.lblDescription.attributedText=[self getData:description];
//Convert HtmlString to string
-(NSAttributedString *)getData:(NSString *)str
{
NSData *stringData = [str dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *options = @{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType};
NSAttributedString *decodedString;
decodedString = [[NSAttributedString alloc] initWithData:stringData
options:options
documentAttributes:NULL
error:NULL];
return decodedString;
}
Upvotes: 1
Reputation: 9599
I got the solution.I tried sample one for your question.I got and it works fine.
NSString *strHTML = @"<style>body{line-height: 0;}</style><font face=\"Calibri\"><b>Get moving!</b> (and Sync to see your points.)</font>";
NSAttributedString *attrStr = [[NSAttributedString alloc] initWithData:[strHTML dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
lblHTMLString.attributedText = attrStr;
The Output Screenshot is
Upvotes: 1