Yumin Hwang Yumin Hwang - 1 year ago 146
Swift Question

How to make custom keyboard work with Swift

i'm making custom keyboard using swift.
the thing i want is that if i key 'a',
'a' can appear on the search bar(safari search bar or somewhere)

i combined all alphabet keys to

@IBAction fun didTapKey

@IBOutlet var key
is that setting shadow for key buttons

this is the part of keyboardViewController.swift.
(pls ignore nextkeyboarbutton, this is not the one i created( i think this is kinda default button ;-; )

class KeyboardViewController: UIInputViewController {
var newKeyboardView: UIView!

@IBAction func didTapKey(sender: UIButton) {


@IBOutlet var key: [UIButton]!

@IBOutlet var nextKeyboardButton: UIButton!

override func updateViewConstraints() {

// Add custom view sizing constraints here

override func viewDidLoad() {


for button in self.key {
button.layer.masksToBounds = false
button.layer.shadowOffset = CGSizeMake(0.0, 2.0)
button.layer.cornerRadius = 4.0
button.layer.shadowColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.25).CGColor
button.layer.shadowOpacity = 1.0
button.layer.shadowRadius = 0.0

Answer Source

When you get the tapped key letter you pass it to the text field the keyboard is currently focused on. The text field you get by:

let textDocumentProxy = self.textDocumentProxy as UIKeyInput

and then you insert your String to that proxy:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download