ios--UITextView在光标处添加文字

来源:互联网 发布:阿里云部署 编辑:程序博客网 时间:2024/06/01 08:41

原文转自:http://blog.sina.com.cn/s/blog_621403ef0100tsvw.html


// 获得光标所在的位置
int location = contentTextView.selectedRange.location;
// 将UITextView中的内容进行调整(主要是在光标所在的位置进行字符串截取,再拼接你需要插入的文字即可)
NSString *content = contentTextView.text;
NSString *result = [NSString stringWithFormat:@"%@[姓名变量]%@",[content substringToIndex:location],[content substringFromIndex:location]];
// 将调整后的字符串添加到UITextView上面
contentTextView.text = result;

0 0
原创粉丝点击