UITextView在textview文本中插入文本 [英] UITextView insert text in the textview text

查看:124
本文介绍了UITextView在textview文本中插入文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想偶尔在UITextView文本对象中插入文本。例如,如果用户按下New Paragraph按钮,我想插入一个双换行符而不是标准的单换行符。

I want to have to occasionally insert text into the UITextView text object. For example, if the user presses the "New Paragraph" button I would like to insert a double newline instead of just the standard single newline.

如何进行?我必须从UITextView读取字符串,改变它,并写回来吗?

How can I go about such? Do i have to read the string from UITextView, mutate it, and write it back? Then how would I know where the pointer was?

感谢

推荐答案

由于 UITextView text 属性是不可变的,因此您必须创建一个新字符串并将text属性设置为。 NSString有一个实例方法( -stringByAppendingString:)用于通过将参数附加到接收者来创建一个新的字符串:

Since the text property of UITextView is immutable, you have to create a new string and set the text property to it. NSString has an instance method (-stringByAppendingString:) for creating a new string by appending the argument to the receiver:

textView.text = [textView.text stringByAppendingString:@"\n\n"];

这篇关于UITextView在textview文本中插入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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