RTF equivalent to UIWebView's loadHTMLString?

空扰寡人 提交于 2019-12-19 10:12:48

问题


Since OS 3.0 UIWebView supports RTF files.

If you have a .rtf file, it's easy enough to load it into a uiwebview, e.g.

NSString *path = [[NSBundle mainBundle] pathForResource:documentName ofType:nil];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];

When loading HTML stored in a string variable, you can use loadHTMLString.

How would one load RTF stored in a string directly into a UIWebView? For example, if you have a string containing {\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf360 {\fonttbl\f0\fswiss\fcharset0 Helvetica;}....., using loadHTMLString will render it literally.

I would like to be able to render RTF from a string variable without having first to save it to a file.


回答1:


Try loadData:MIMEType:textEncodingName:baseURL:. Haven't tried it, but it's worth a shot.



来源:https://stackoverflow.com/questions/7258502/rtf-equivalent-to-uiwebviews-loadhtmlstring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!