Visualizo html en UITextView
por:
[self.textView setValue:@"<b>Content</b>" forKey:@"contentToHTMLString"];
,
Después de editar contenido en UITextView
, quiero que el contenido incluya html, así que uso:
[self.textView valueForKey:@"contentToHTMLString"];
pero la aplicación falla, ¿cómo solucionarlo?
Para iOS 7, use el siguiente código.
NSString *htmlString = @"<h1>Header</h1><h2>Subheader</h2><p>Some <em>text</em></p><img src='http://blogs.babble.com/famecrawler/files/2010/11/mickey_mouse-1097.jpg' width=70 height=100 />"; NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil]; textView.attributedText = attributedString;
Según Display html text en uitextview esta pregunta Use una UIWebView
.
Porque no está documentado – [UITextView setContentToHTMLString:] método. La aplicación será rechazada por usar methods no documentados.
Pero aún así quieres hacer esto, puedes echar un vistazo a estos enlaces. Podría ser de ayuda: –
https://github.com/AliSoftware/OHAttributedLabel
https://www.cocoacontrols.com/controls/bctextview
https://www.cocoacontrols.com/controls/egotextview
y para hacer esta tarea con UIWebview debe mirar esto:
Rich-text-editing-sample-project
NSString *htmlContentString = self.compnayInfoPageDictionary[@"tDescription"]; [self.txtViewInfoPage setValue:htmlContentString forKey:@"contentToHTMLString"];