I have a HTML contents with achor tag in it. I just want to load that HTML content in UITextView
.
Asked
Active
Viewed 3,050 times
2

rmaddy
- 314,917
- 42
- 532
- 579

Kirti Parghi
- 1,142
- 3
- 14
- 31
-
View this http://stackoverflow.com/questions/18608060/get-html-in-uitextview – pcs Apr 26 '15 at 08:24
1 Answers
3
You can convert an HTML document to NSAttributedString
like so:
// The HTML needs to be in the form of an NSString
NSError *error = nil;
NSAttributedString *attString = [[NSAttributedString alloc] initWithData:[HTML dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute:@(NSUTF8StringEncoding)} documentAttributes:nil error:&error];
if (error) {
NSLog(@"Error: %@ %s %i", error.localizedDescription, __func__, __LINE__);
} else {
// Clear text view
textView.text = @"";
// Append the attributed string
[textView.textStorage appendAttributedString:attString];
}
If you come across any problems then try changing the encoding to NSASCIIStringEncoding
in all places.

Rob Sanders
- 5,197
- 3
- 31
- 58