I have the below code that runs on iPad successfully.
func setupLockPinSection() {
let keys = ["1", "2","3", "4","5", "6","7", "8","9", "0", "Clear", "Done"]
let kbFrame = CGRect(x: 0, y: 0, width: view.frame.width, height: 400)
if let customKeyboard = Bundle.main.loadNibNamed("MACustomKeyboard", owner: self, options: nil)?.first as? MACustomKeyboard {
customKeyboard.frame = kbFrame
customKeyboard.setKeyboardButtons(keys)
lockPin1.inputView = customKeyboard
//Number Tapped
customKeyboard.numberTappedBlock = { [weak self] view, text in
if let textFieldText = self?.lockPin1.text, let t = text {
self?.lockPin1.text = textFieldText + t
}
}
//Done button Tapped
customKeyboard.doneTappedBlock = { [weak self] view in
self?.lockPin1.resignFirstResponder()
}
//Clear Button Tapped
customKeyboard.clearTappedBlock = { [weak self] view in
if let text = self?.lockPin1.text, text.characters.count > 0 {
self?.lockPin1.text = text.substring(to: text.index(text.endIndex, offsetBy: -1))
}
}
}
if let customKeyboard = Bundle.main.loadNibNamed("MACustomKeyboard", owner: self, options: nil)?.first as? MACustomKeyboard {
customKeyboard.frame = kbFrame
customKeyboard.setKeyboardButtons(keys)
lockPin2.inputView = customKeyboard
//Number Tapped
customKeyboard.numberTappedBlock = { [weak self] view, text in
if let textFieldText = self?.lockPin2.text, let t = text {
self?.lockPin2.text = textFieldText + t
}
}
//Done button Tapped
customKeyboard.doneTappedBlock = { [weak self] view in
self?.lockPin2.resignFirstResponder()
}
//Clear Button Tapped
customKeyboard.clearTappedBlock = { [weak self] view in
if let text = self?.lockPin2.text, text.characters.count > 0 {
self?.lockPin2.text = text.substring(to: text.index(text.endIndex, offsetBy: -1))
}
}
}
lockPin1.text = UserDefaults.standard.string(forKey: "lockPin")
lockPin2.text = UserDefaults.standard.string(forKey: "lockPin")
}
I want to make the clear and done button like the ones on iOS default keyboard with the displaying images (hiding keyboard button, clear button). I want to do this because, for my lock pin functionality I just want to use digits, and on iPad it does not allow that. Hence I need to make it customized keyboard.