简体   繁体   English

如何从iPhone App中的URL读取.rtf文件

[英]How to read .rtf File from URL in iPhone App

My app needs to read .rtf file from URL. 我的应用程序需要从URL读取.rtf文件。 I am going to read it as 我要读成

    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@.rtf",_URL]];
    NSError* error;
    NSString *content = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error];

Now when I load this text in UITextView. 现在,当我在UITextView中加载此文本时。 It gives me tags with { and / characters with the original file text. 它为我提供了带有{和/字符以及原始文件文本的标签。 Please guide me that how can i read the right text which did not include any brackets and html data. 请指导我如何阅读正确的文本,其中不包含任何方括号和html数据。

.rtf file always contains Tags with itself for formating text color alignment and other properties.. .rtf文件始终包含带有用于格式化文本颜色对齐方式和其他属性的标签。

please open that .rtf file in to text edit and convert all text part of that file to simple text. 请打开该.rtf文件进行文本编辑,然后将该文件的所有文本部分转换为简单文本。

then your existing code will work. 那么您现有的代码将起作用。

else instead of taking the UItextView open it in UIWebview. 否则,请不要使用UItextView在UIWebview中打开它。

hope it will be helpfull for you. 希望对您有帮助。

You can use RTF in a UITextView by first transforming it into an NSAttributedString and then setting the value of the UITextView's attributedString property to the NSAttributedString. 您可以在UITextView中使用RTF,方法是先将其转换为NSAttributedString,然后将UITextView的attributedString属性的值设置为NSAttributedString。

NSAttributedString *stringWithRTF = [[NSAttributedString alloc]   initWithFileURL:rtfDoc options:@{NSDocumentTypeDocumentAttribute: NSRTFTextDocumentType} documentAttributes:nil error:nil];

// Instantiate UITextView object
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(20,20,self.view.frame.size.width,self.view.frame.size.height)];

textView.attributedText=stringWithRTF;

[self.view addSubview:textView];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM