Search code examples
iosobjective-ckeyboarduiinputviewcontroller

How do i add an inputAccessoryView to a Custom Keyboard (ios Extension)


I've created a custom keyboard programmatically. There is no Storyboard. I'd like to add an Accessory View above as per Apple's own keyboard. Can't figure out how to do this in swift inside my Keyboard file within my app.

I tried (row0 is a UIView):

self.view.inputAccessoryView?.addSubview(row0)

Thanks!


Solution

  • You don't do this in a custom keyboard - the inputAccessoryView is something that the app itself (the one controlling the text field you're entering text into) adds above whatever keyboard is in use. If you need more height for your keyboard, you can use this code (copied from Apple's App Extension Programming Guide):

    CGFloat _expandedHeight = 500; // this is the height you want your keyboard to be
    NSLayoutConstraint *_heightConstraint = 
        [NSLayoutConstraint constraintWithItem: self.view 
                                     attribute: NSLayoutAttributeHeight 
                                     relatedBy: NSLayoutRelationEqual 
                                        toItem: nil 
                                     attribute: NSLayoutAttributeNotAnAttribute 
                                    multiplier: 0.0 
                                      constant: _expandedHeight];
    [self.view addConstraint: _heightConstraint];