I have made a custom keyboard using a .xib and .swift file. I set it for a textfield by doing the following:
let customNumberPad = CustomNumberPad()
length.inputView = customNumberPad.inputView
However, the size of the keyboard area is large like it is using the old keyboard.
I have tried setting the height in the .xib to 200 via constraint.
I have tried:
length.inputView!.autoresizingMask = []
let heightAnch = length.inputView!.heightAnchor.constraint(equalToConstant: 200)
heightAnch.isActive = true
length.reloadInputViews()
Full CustomNumberPad code:
import UIKit
import AudioToolbox
class CustomNumberPadSmall: UIInputViewController {
@IBOutlet var numberPad: UIView!
@IBAction func insertText(_ sender: UIButton) {
if let text = sender.currentTitle {
AudioServicesPlaySystemSound (1104)
self.textDocumentProxy.insertText(text)
}
}
@IBAction func backSpace(_ sender: UIButton) {
self.textDocumentProxy.deleteBackward()
}
override func viewDidLoad() {
super.viewDidLoad()
overrideUserInterfaceStyle = USERINFO.darkModeValue
Bundle.main.loadNibNamed("CustomNumberPadSmall", owner: self)
numberPad.translatesAutoresizingMaskIntoConstraints = false
let inputView = self.inputView!
inputView.translatesAutoresizingMaskIntoConstraints = false
inputView.addSubview(numberPad)
NSLayoutConstraint.activate([
numberPad.topAnchor.constraint(equalTo: inputView.topAnchor),
numberPad.bottomAnchor.constraint(equalTo: inputView.bottomAnchor),
numberPad.leadingAnchor.constraint(equalTo: inputView.leadingAnchor),
numberPad.trailingAnchor.constraint(equalTo: inputView.trailingAnchor),
numberPad.heightAnchor.constraint(equalToConstant: 200)
])
}
}