UITextView with HTML text

suggest change

Creating 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];

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents