Skip to content

Instantly share code, notes, and snippets.

@tunitowen
Last active June 24, 2017 17:27
Show Gist options
  • Save tunitowen/9599186 to your computer and use it in GitHub Desktop.
Save tunitowen/9599186 to your computer and use it in GitHub Desktop.
HTML to NSAttributedString
NSString *html = @"<div style='font: 18pt Helvetica-Light; color: #3498DB;'>Blue Text<span style='color: #AAAAAA;'>GreyText</span></div>"];
NSData *htmlData = [html dataUsingEncoding:NSUTF8StringEncoding];
NSMutableAttributedString *htmlAttributedString = [[NSMutableAttributedString alloc] initWithData:htmlData options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType} documentAttributes:nil error:nil];
[label setAttributedText:htmlAttributedString];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment