Last active
June 22, 2018 03:01
-
-
Save jamesaq12wsx/b3fe81ee89c12ffa144a3e13c07ad8a6 to your computer and use it in GitHub Desktop.
[swift]建立App內部鍵盤
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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