Swift:在NSTextField中设置插入点 [英] Swift: Set Insertion Point in NSTextField
本文介绍了Swift:在NSTextField中设置插入点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有一些文本"sometext"的NSTextField.如何以编程方式将光标置于e和t:"some | text"之间?
I have a NSTextField with some text "sometext". How can I place the cursor between e and t: "some|text" programmatically?
推荐答案
您需要将文本字段设置为当前编辑器选择的range属性.尝试这样:
You need to set your text field current editor selected range property. Try like this:
textField.currentEditor()?.selectedRange = NSRange(location: 4, length: 0)
您将需要致电displayIfNeeded
You will need to call displayIfNeeded
textField.displayIfNeeded()
这篇关于Swift:在NSTextField中设置插入点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文