I've made an in-app custom keyboard that replaces the system keyboard and pops up when I tap inside a UITextField
.
Here is my code:
class ViewController: UIViewController {
var myCustomKeyboard: UIView!
@IBOutlet weak var textField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
let keyboardNib = UINib(nibName: "Keyboard", bundle: nil)
myCustomKeyboard = keyboardNib.instantiateWithOwner(self, options: nil)[0] as! UIView
textField.inputView = myCustomKeyboard
}
}
The keyboard layout is loaded from an xib file.
Question
How do I get the button text into the text field?
Notes:
- There are many tutorials about making a custom system keyboard (which needs to be installed), but I only want an in-app keyboard. The tutorials use a special view controller just for the keyboard, but here it seems that I am just setting the keyboard view.
- I have read the Custom Views for Data Input documentation.
- This is the closest Stack Overflow question I could find, but it doesn't go as far as describing how to get the text from the buttons.
Update
- This tutorial seems to indicate that there is a view controller for the custom input view. However, I am getting lost in the Objective-C code. What would be the process in Swift?
- This answer mentions the
UIKeyInput
protocol thatUITextField
conforms to, but how do I use it? - If there is any built in way too make a custom in-app keyboard, I would really prefer that to making a normal custom view.