title: iOS 8 Custom Keyboard appear pretty slow
body: <p>I am trying to build a custom keyboard using Swift for iOS 8 and I created each button programatically. When switching to my custom keyboard from build-in keyboard, the first time it's pretty slow as it took like 2 seconds to appear. I am not entirely sure if I am doing it correctly. Below are my code and I just show 2 buttons but there are a lot more:</p>
  
  <pre><code>class KeyboardViewController: UIInputViewController {
  
      @IBOutlet var nextKeyboardButton: UIButton!
      @IBOutlet var qButton: UIButton!
  
      var buttonFontSize:CGFloat = 22.0
      var gapBtwButton:CGFloat = +7.0
      // a lot more button below
  
      override func updateViewConstraints() {
          super.updateViewConstraints()
  
          // Add custom view sizing constraints here
      }
  
      override func viewDidLoad() {
  
          super.viewDidLoad()
  
          setupEnKeyboard()
  
      }
  
  
      func setupEnKeyboard(){
  
          println("setupEnKeyboard")
  
          addEnKeyboardButtons()
  
      }
  
      func addEnKeyboardButtons() {
  
          addQButton()
  
          addNextKeyboardButton()
  
          // a lot more button to be added
  
      }
  
      func setupButton(label: String, functionName: Selector, imageOnButton: String) -&gt; UIButton {
  
          // initialize the button
          let keyButton:UIButton = UIButton.buttonWithType(.System) as UIButton
  
          var testVar: String? = imageOnButton
  
          if imageOnButton.isEmpty {
  
              keyButton.setTitle(label, forState: .Normal)
  
          } else {
  
              let image = UIImage(named: imageOnButton) as UIImage
  
              keyButton.setImage(image, forState: .Normal)
  
          }
  
          keyButton.sizeToFit()
          keyButton.setTranslatesAutoresizingMaskIntoConstraints(false)
  
          // adding a callback
          keyButton.addTarget(self, action: functionName, forControlEvents: .TouchUpInside)
  
          // make the font bigger
          keyButton.titleLabel?.font = UIFont.systemFontOfSize(self.buttonFontSize)
  
          // add rounded corners
          keyButton.backgroundColor = UIColor(white: 0.9, alpha: 1)
          keyButton.setTitleColor(UIColor.blackColor(), forState: .Normal)
          keyButton.layer.cornerRadius = 5
  
          return keyButton
  
      }
  
      func addQButton() {
  
          qButton = setupButton("Q", functionName:"didTapQButton", imageOnButton:"")
  
          view.addSubview(qButton)
  
          var leftSideConstraint = NSLayoutConstraint(item: qButton, attribute: .Left, relatedBy: .Equal, toItem: view, attribute: .Left, multiplier: 1.0, constant: +6.0)
  
          var topConstraint = NSLayoutConstraint(item: qButton, attribute: .Top, relatedBy: .Equal, toItem: view, attribute: .Top, multiplier: 1.0, constant: +10.0)
  
          view.addConstraints([leftSideConstraint, topConstraint])
  
      }
  
      func didTapQButton(){
  
          var proxy = textDocumentProxy as UITextDocumentProxy
  
          proxy.insertText("q")
  
      }
  
  
      func addNextKeyboardButton() {
  
          nextKeyboardButton = setupButton("N", functionName:"advanceToNextInputMode", imageOnButton:"globe")
  
          view.addSubview(nextKeyboardButton)
  
          var leftSideConstraint = NSLayoutConstraint(item: nextKeyboardButton, attribute: .Left, relatedBy: .Equal, toItem: showNumbersButton, attribute: .Right, multiplier: 1.0, constant: self.gapBtwButton)
  
          var bottomConstraint = NSLayoutConstraint(item: nextKeyboardButton, attribute: .Bottom, relatedBy: .Equal, toItem: view, attribute: .Bottom, multiplier: 1.0, constant: -3.0)
  
          view.addConstraints([leftSideConstraint, bottomConstraint])
  
      }    
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated
      }
  
      override func textWillChange(textInput: UITextInput) {
          // The app is about to change the document's contents. Perform any preparation here.
      }
  
      override func textDidChange(textInput: UITextInput) {
          // The app has just changed the document's contents, the document context has been updated.
  
          var textColor: UIColor
          var proxy = self.textDocumentProxy as UITextDocumentProxy
          if proxy.keyboardAppearance == UIKeyboardAppearance.Dark {
              textColor = UIColor.whiteColor()
          } else {
              textColor = UIColor.blackColor()
          }
          //self.nextKeyboardButton.setTitleColor(textColor, forState: .Normal)
      }
  
  }
  </code></pre>
  
  <p>Appreciate any comment please :)</p>
  
  <p>Thanks,
  Mark Thien</p>