1.根据NSRange 转换成 NSTextRange
UITextPosition *beginning = textView.beginningOfDocument;
UITextPosition *start = [textView positionFromPosition:beginning offset:range.location];
UITextPosition *end = [textView positionFromPosition:start offset:range.length];
UITextRange *textRange = [textView textRangeFromPosition:start toPosition:end]];
2.根据NSTextRange 转换成 NSRange
UITextPosition* beginning = textField.beginningOfDocument;
UITextRange* selectedRange = textField.selectedTextRange;
UITextPosition* selectionStart = selectedRange.start;
UITextPosition* selectionEnd = selectedRange.end;
const NSInteger location = [textField offsetFromPosition:beginning toPosition:selectionStart];
const NSInteger length = [textField offsetFromPosition:selectionStart toPosition:selectionEnd];