I created a custom keyboard using buttons, but now I'm stuck with buttons that don't do anything.
How will I connect them to a text field?
I created a custom keyboard using buttons, but now I'm stuck with buttons that don't do anything.
How will I connect them to a text field?
First, you should be aware of the inputView property of the UITextField
/UITextView
classes. Basically you can have a custom view (your keyboard for example) and swap it with the default keyboard.
You can get some inspiration from this tutorial that shows how to create a custom keyboard - and how to connect it to your textfield
/textview
.
You can also read this answer for another way to connect your keyboard to a textfield/textview.
You can handle buttons touchUpInside Action like this to insert text in uitextfield
@IBAction func btnQuestionAction(_ sender: UIButton)
{
self.textDocumentProxy.insertText("?")
}
And to delete character using custom keyboard, You can use this:
@IBAction func btnBackspaceAction(_ sender: UIButton)
{
self.textDocumentProxy.deleteBackward()
}
Hope it will help you :)