码迷,mamicode.com
首页 > 其他好文 > 详细

删除光标前的字符

时间:2015-05-06 12:44:48      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:

 UITextPosition* beginning = _commentTextView.beginningOfDocument;
    
    UITextRange* selectedRange = _commentTextView.selectedTextRange;
    UITextPosition* selectionStart = selectedRange.start;
    
    //获取光标所在位置
    NSInteger location = [_commentTextView offsetFromPosition:beginning toPosition:selectionStart];
    
    NSRange range = NSMakeRange(location-1, 1);
NSString *newText = [_commentTextView.text stringByReplacingCharactersInRange:range withString:@""];
_commentTextView.text = newText;
//重新设置光标的位置
_commentTextView.selectedRange = NSMakeRange(location-1, 0);

 

删除光标前的字符

标签:

原文地址:http://www.cnblogs.com/damiao/p/4481271.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!