2

I've created custom keyboard and it works fine. But I don't know how to set my custom keyboard to specific UITextField. This is my KeyboardViewController

import UIKit

class KeyboardViewController: UIInputViewController {

    @IBOutlet var nextKeyboardButton: UIButton!
    @IBOutlet weak var percentView: UIView!
    @IBOutlet weak var hideKeyboardButton: UIButton!

    override func updateViewConstraints() {
        super.updateViewConstraints()

        // Add custom view sizing constraints here
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        // Perform custom UI setup here
        self.nextKeyboardButton = UIButton(type: .System)

        self.nextKeyboardButton.setTitle(NSLocalizedString("Next Keyboard", comment: "Title for 'Next Keyboard' button"), forState: .Normal)
        self.nextKeyboardButton.sizeToFit()
        self.nextKeyboardButton.translatesAutoresizingMaskIntoConstraints = false

        self.nextKeyboardButton.addTarget(self, action: "advanceToNextInputMode", forControlEvents: .TouchUpInside)

        self.view.addSubview(self.nextKeyboardButton)


        let nextKeyboardButtonLeftSideConstraint = NSLayoutConstraint(item: self.nextKeyboardButton, attribute: .Left, relatedBy: .Equal, toItem: self.view, attribute: .Left, multiplier: 1.0, constant: 0.0)
        let nextKeyboardButtonBottomConstraint = NSLayoutConstraint(item: self.nextKeyboardButton, attribute: .Bottom, relatedBy: .Equal, toItem: self.view, attribute: .Bottom, multiplier: 1.0, constant: 0.0)
        self.view.addConstraints([nextKeyboardButtonLeftSideConstraint, nextKeyboardButtonBottomConstraint])

        let nib = UINib(nibName: "KeyboardView", bundle: nil)
        let objects = nib.instantiateWithOwner(self, options: nil)
        view = objects[0] as! UIView;

        for view in self.view.subviews {
            if let btn = view as? UIButton {
                btn.layer.cornerRadius = 5.0
                btn.translatesAutoresizingMaskIntoConstraints = false
                //btn.addTarget(self, action: "keyPressed:", forControlEvents: .TouchUpInside)
            }
        }
    }

and other delegate methods. So how can I call this ? Actually the problem is I couldn't import custom keyboard classes from app extension. That's the main problem. I did this all build phases stuff. And I can use the keyboard if I change keyboard myself.

letitbefornow
  • 427
  • 6
  • 20
  • Are you looking to add a custom font to the UITextField or just use that keyboard for the specific text field? – Caleb Bach Nov 03 '15 at 09:16
  • Nope. I've created number keypad as a custom keyboard for iPad application. So I need to set this keyboard to some specific UITextFileds to default keyboard. – letitbefornow Nov 03 '15 at 09:19
  • You might find your answer here, [customkeyboard](http://stackoverflow.com/questions/33474771/a-swift-example-of-custom-views-for-data-input-custom-in-app-keyboard) – DevNinja Aug 30 '16 at 14:16

1 Answers1

2

According Apple Documentation

After a user chooses a custom keyboard, it becomes the keyboard for every app the user opens.

Therefor it's not like your app specific thing, it's more like different languages keyboards. As far as you can't specify some specific language keyboard for your UITextField or UITextView you can't specify your custom keyboard as well.

Are you sure that you need Custom Keyboard instead of custom view for data input inside your app? About custom data input views you can read here.

iyuna
  • 1,787
  • 20
  • 24
  • Actually in obj-c I can do that also. But the problem is I couldn't import custom keyboard classes from app extension. That's the main problem. – letitbefornow Nov 04 '15 at 14:52