UITextView with HTML text
suggest changeCreating an HTML attributed string must be done on the main thread. Raleway-Regular must be registered with the app, or fontWithName:size: returns nil. Setting font afterward applies that one font to the whole string and removes the HTML bold.
NSString *htmlString = @"<p> This is an <b>HTML</b> text</p>";
NSAttributedString *attributedString = [[NSMutableAttributedString alloc]
initWithData: [htmlString dataUsingEncoding:NSUnicodeStringEncoding]
options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType }
documentAttributes: nil
error: nil
];
_yourTextView.attributedText = attributedString;
// If you want to modify the font
_yourTextView.font = [UIFont fontWithName:@"Raleway-Regular" size:15];
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents