在UITextView中显示没有\\\<br/>的段落 [英] Display Paragraphs in UITextView without \n

查看:130
本文介绍了在UITextView中显示没有\\\<br/>的段落的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个方便的方式来格式化一个相当长的字符串与其中的段落(如下),使它与 \\\
,因此textView将显示段落?

  blah 

blah

@blah\\\
\\\
blah


解决方案

下面是一个简单的例子假设你有:




  • 一个名为的文件:myfile.txt

  • 用于保存文件内容的字符串变量,我们将其命名为:content

  • 一个UITextView调用:textView



在你的文本文件中写任何你想要的东西,从Xcode下的Ressources中导入它),然后在代码中的某个地方(init方法或动作):

  NSString * path = [[NSBundle mainBundle] pathForResource:@myfile
ofType:@txt];
NSString * content = [NSString stringWithContentsOfFile:path
encoding:NSUTF8StringEncoding
error:NULL];

textView.text = content;


Is there a convenient way to format a rather long string with paragraphs in it (like below) to have it with \n in it so the textView will display the paragraphs as well?

blah

blah

to @"blah\n\nblah"

Thanks!

解决方案

Here's a simple example assuming you have :

  • A file named : myfile.txt
  • A string variable to hold the file's content, let's name it : content
  • A UITextView called :textView

Write whatever you want in your text file and place it wherever you want in your Xcode project (usually import it from within Xcode under "Ressources"), and then somewhere in your code (init method or action) :

NSString *path = [[NSBundle mainBundle] pathForResource:@"myfile" 
                                                 ofType:@"txt"];
NSString *content = [NSString stringWithContentsOfFile:path 
                                              encoding:NSUTF8StringEncoding 
                                                 error:NULL];

textView.text = content; 

这篇关于在UITextView中显示没有\\\<br/>的段落的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆