i具有以下代码成功在iPad上运行的代码。
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")
}
我想用显示图像(隐藏键盘按钮,清除按钮(,像iOS默认键盘上的清除和完成按钮一样。我想这样做,因为,对于我的锁定PIN功能,我只想使用数字,而在iPad上,它不允许使用。因此,我需要制作自定义的键盘。
这是我现在使用上述代码
键盘向下按钮(右下角的按钮(和清除按钮(右上角的按钮(,我想在自定义键盘中实现它们,这样我就有它们,而不是我的"清除"one_answers"完成"按钮
这就是我想完成的!