ios - How to load HTML in UITextView? -
i have html contents achor tag in it. want load html content in uitextview
.
you can convert html document nsattributedstring
so:
// html needs in form of 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 attributed string [textview.textstorage appendattributedstring:attstring]; }
if come across problems try changing encoding nsasciistringencoding
in places.
Comments
Post a Comment