To run the example project, clone the repo, and run pod install
from the Example directory first.
- Xcode 9.0+
- iOS 8.0+
Keyboard is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'KeyboardSwift'
import KeyboardSwift
You can use Keyboard in UIViewController
or any UIView
with inputAccessoryView
(UITextField
, UISearchBar
, UITextView
). Simply call keyboard
and configure it with the items you want. An example:
let cancelItem = KeyboardItem.barButton(title: "Cancel", style: .plain) { item in
// Called when cancel item is tapped
self.textView.endEditing(true)
}
let countLabel = UILabel()
countLabel.text = "0"
let labelItem = KeyboardItem.custom(view: countLabel)
let doneItem = KeyboardItem.barButton(title: "Done", style: .done) { item in
// Called when done item is tapped
self.textView.endEditing(true)
}
textView.keyboard.with(items: cancelItem, .flexibleSpace, labelItem, .flexibleSpace, doneItem)
/// Default bar button item
case barButton(title: String, style: UIBarButtonItemStyle, action: UIBarButtonItemTargetClosure?)
/// System bar button item
case systemBarButton(system: UIBarButtonSystemItem, action: UIBarButtonItemTargetClosure?)
/// Flexible space
case flexibleSpace
/// Fixed space
case fixedSpace(width: CGFloat)
/// Custom view
case custom(view: UIView)
You can customize the accessoryView
calling customize
method:
textView.keyboard.customize { (toolbar, items) in
toolbar.isTranslucent = false
toolbar.tintColor = .purple
}
Only available in UIViewController
or subclass:
case willShow
case willHide
case didShow
case didHide
Example:
override func viewDidLoad() {
super.viewDidLoad()
// Subscribe
self.keyboard.subscribe(to: .willShow) { sender in
// TODO: something to do when keyboard will be shown
}
// ...
// Unsubscribe
self.keyboard.unsubscribe()
}
adboco@telefonica.net, Adrián Bouza Correa
Keyboard is available under the MIT license. See the LICENSE file for more info.