Control cursor position in UITextField

后端 未结 7 2178
你的背包
你的背包 2020-11-29 00:52

I have a UITextField that I\'m forcing formatting on by modifying the text inside the change notification handler. This works great (once I solved the reentranc

7条回答
  •  萌比男神i
    2020-11-29 01:08

    Here's the Swift version of @Chris R. – updated for Swift3

    private func selectTextForInput(input: UITextField, range: NSRange) {
        let start: UITextPosition = input.position(from: input.beginningOfDocument, offset: range.location)!
        let end: UITextPosition = input.position(from: start, offset: range.length)!
        input.selectedTextRange = input.textRange(from: start, to: end)
    }
    

提交回复
热议问题