Control cursor position in UITextField

后端 未结 7 2193
你的背包
你的背包 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条回答
  •  余生分开走
    2020-11-29 01:31

    I've finally found a solution for this problem! You can put the text you need inserted into the system pasteboard and then paste it at the current cursor position:

    [myTextField paste:self]  
    

    I found the solution on this person's blog:
    http://dev.ragfield.com/2009/09/insert-text-at-current-cursor-location.html

    The paste functionality is OS V3.0 specific, but I've tested it and it works fine for me with a custom keyboard.

    If you go for this solution then you should probably save the user's existing clipboard contents and restore them immediately afterwards.

提交回复
热议问题