Customize the nib file with the appropriate input layout and input elements. In my case, I set each button to act with the file owner of inputViewButtonPressed .
Set up a storyboard (or, if you want, nib, if you want) for the view controller.
Then, using the following code, you should get what you are looking for:
class ViewController: UIViewController, UITextFieldDelegate { var myInputView : UIView! var activeTextField : UITextField? override func viewDidLoad() { super.viewDidLoad()
Alternatively, if you want to be more like a keyboard, you can use this function as your action (it uses the new let syntax from Swift 1.2), break it down if you need 1.1 compatibility:
@IBAction func insertButtonText(button:UIButton) { if let textField = activeTextField, title = button.titleLabel?.text, range = textField.selectedTextRange {
The UITextInput protocol is UITextInput to update a text field. Deletion handling is a bit more complicated, but still not so bad:
@IBAction func deleteText(button:UIButton) { if let textField = activeTextField, range = textField.selectedTextRange { if range.empty {
source share