Skip to content

Instantly share code, notes, and snippets.

View jamesaq12wsx's full-sized avatar

James Lin jamesaq12wsx

View GitHub Profile
@jamesaq12wsx
jamesaq12wsx / ViewController.swift
Created June 22, 2018 02:56
[swift]建立App內部鍵盤->設定KeyboardAccessory
override func viewDidLoad() {
//...
let keyboardAccessoryView = CustomAccessoryView(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
keyboardAccessoryView.delegate = self
textField.inputAccessoryView = keyboardAccessoryView
}
@jamesaq12wsx
jamesaq12wsx / MyKeyboard.swift
Created June 22, 2018 01:53
[swift]建立App內部鍵盤
//1
protocol KeyboardDelegate: class {
func keyWasTapped(input: Int)
}
class MyKeyboard: UIView {
//2
@IBOutlet weak var Btn1: UIButton!
@IBOutlet weak var Btn2: UIButton!
@jamesaq12wsx
jamesaq12wsx / ViewController.swift
Last active June 22, 2018 02:57
[swift]建立App內部鍵盤->實作switchKeyboard
func switchKeyboard() {
print("switch keyboard")
textField.endEditing(true);
if textField.inputView == nil {
textField.inputView = myKeyBoard
}else{
textField.inputView = nil
}
textField.becomeFirstResponder()
}
@jamesaq12wsx
jamesaq12wsx / CustomAccessoryView.swift
Last active June 22, 2018 01:46
[swift]建立App內部鍵盤
protocol SwitchKeyboardDelegate: class {
func switchKeyboard()
}
class CustomAccessoryView: UIView {
weak var delegate: SwitchKeyboardDelegate!
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
@jamesaq12wsx
jamesaq12wsx / ViewController.swift
Last active June 22, 2018 03:01
[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為自定義鍵盤