Swift: Set Insertion Point in NSTextField

别等时光非礼了梦想. 提交于 2019-12-18 09:37:39

问题


I have a NSTextField with some text "sometext". How can I place the cursor between e and t: "some|text" programmatically?


回答1:


You need to set your text field current editor selected range property. Try like this:

textField.currentEditor()?.selectedRange = NSRange(location: 4, length: 0)

You will need to call displayIfNeeded

textField.displayIfNeeded()


来源:https://stackoverflow.com/questions/34246319/swift-set-insertion-point-in-nstextfield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!