📱

UITextFieldで途中の文字を変更したい時のTips

2021/04/29に公開

UITextInput.replace(_:_) が使えるよというお話し。

textField.text = (text as NSString).replacingCharacters(in: range, with: someText)

とやってしまうと、カーソルが一番後ろに行ってしまって、使いにくくなる。

そこで、UITextInput.replace(_:_) を使う。

参考:
https://gist.github.com/kothihaaung/4b99eb293b702d1c965692d7af20d5c5

Discussion