Swift: Set Insertion Point in NSTextField

前端 未结 1 637
清酒与你
清酒与你 2020-12-22 03:33

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

相关标签:
1条回答
  • 2020-12-22 04:19

    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()
    
    0 讨论(0)
提交回复
热议问题