2

I use a custom keyboard which contains a delete and a clear button.I can able to delete the letters using this code

let obj =  UIInputViewController()
(obj.textDocumentProxy as UIKeyInput).deleteBackward()

Is it any keyword available to clear whole text in a textfield.

NB: I found this link but it is not apt for my requirement

Community
  • 1
  • 1
Kiran P Nair
  • 2,041
  • 22
  • 31

1 Answers1

3

There is no keyword available for deleting the whole text in the textfield through custom keyboard.

To clear all the text that the UITextDocumentProxy object can access in the textfield before the cursor position

if let word:String = self.textDocumentProxy.documentContextBeforeInput     
{
    for _: Int in 0 ..< word.characters.count {
        self.textDocumentProxy.deleteBackward()
    }
}

To delete the text after cursor position, you have to move the cursor forward to delete it.

KrishnaCA
  • 5,615
  • 1
  • 21
  • 31