UITextView在光标处添加文字

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

posted @ 2015-12-24 08:07  Bo-tree  阅读(216)  评论(0)    收藏  举报