Skip to content

Instantly share code, notes, and snippets.

@jamesaq12wsx
Last active June 22, 2018 03:01
Show Gist options
  • Save jamesaq12wsx/b3fe81ee89c12ffa144a3e13c07ad8a6 to your computer and use it in GitHub Desktop.
Save jamesaq12wsx/b3fe81ee89c12ffa144a3e13c07ad8a6 to your computer and use it in GitHub Desktop.
[swift]建立App內部鍵盤
//ViewController 繼承 KeyboardDelegate
ViewController: UIViewController, KeyboardDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
// 初始化鍵盤
let keyboardView = MyKeyboard(frame: CGRect(x: 0, y: 0, width: 0, height: 300))
// 當鍵盤有按鍵按下後,會通知ViewController
keyboardView.delegate = self
// 設定input為自定義鍵盤
textField.inputView = keyboardView
}
//並實作KeyboardDelegate中的keyWasTapped
//實作delegate
func keyWasTapped(input: Int) {
textField.insertText(String(input))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment