【发布时间】:2018-04-23 06:06:20
【问题描述】:
我的函数想在 textview 中获取光标当前位置,但是当我在 textview 中有字符串“???? ???? ????”(光标在最后一个位置)时,它返回给我范围(0, 6)当前索引为6,预期位置为3,请告诉我是否有任何方法可以获取光标位置
func getcurserforTextView(textView : UITextView ) -> Int {
var cursorPosition = 0
if let selectedRange = textView.selectedTextRange {
cursorPosition = textView.offset(from: textView.beginningOfDocument, to: selectedRange.start)
}
return cursorPosition
}
【问题讨论】:
标签: ios swift nsstring uitextview