删除光标前的字符

 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);

 

posted @ 2015-05-06 11:02  嗷大喵  阅读(948)  评论(0编辑  收藏  举报